OrchardCMS/OrchardCore · error · TypeError
@@toPrimitive must return a primitive value.
Error message
@@toPrimitive must return a primitive value.
What it means
Internal helper in the bundled Font Awesome UMD bundle: _toPrimitive calls the value's Symbol.toPrimitive method and the result is an object instead of a primitive. This is a transpiled runtime invariant failure, not an Orchard Core error — it occurs only when consumer script passes exotic objects into Font Awesome APIs. Fix by updating the vendored fontawesome package or reporting upstream.
Solutions
- Ensure Symbol.toPrimitive returns a primitive value
- Audit and remove polyfills that override Symbol/Object prototype behavior
- Regenerate or update the regular.js vendor bundle
Example fix
// before key[Symbol.toPrimitive] = () => new Object(); // after key[Symbol.toPrimitive] = (hint) => hint === 'string' ? 'key' : 1;
Defensive patterns
Strategy: type-guard
Validate before calling
function safeKey(o) { if (typeof o?.[Symbol.toPrimitive] === 'function') { const r = o[Symbol.toPrimitive]('string'); if (typeof r === 'object') throw new TypeError('toPrimitive returned object'); return r; } return o; } Type guard
function hasPrimitiveToPrimitive(o) { const f = o?.[Symbol.toPrimitive]; return typeof f !== 'function' || ['string','number','symbol'].includes(typeof f.call(o, 'string')); } Try / catch
try { loadRegularIcons(); } catch (e) { if (e instanceof TypeError && e.message.includes('toPrimitive')) console.error('Polyfill conflict detected'); } Prevention
- Audit global polyfills for Symbol.toPrimitive overrides
- Keep fontawesome.js and regular.js from the same Font Awesome version
- Test icon bundles with the site's full polyfill set
When it happens
Trigger: A computed property / key conversion in regular.js hitting an object whose Symbol.toPrimitive(hint) returns {} or another non-primitive.
Common situations: Global polyfill conflicts; monkey-patching Object/Symbol prototypes on the page; corrupted or mismatched vendor bundles shipped together.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- @@toPrimitive must return a primitive value.
- @@toPrimitive must return a primitive value.
- Super expression must either be null or a function
- @@toPrimitive must return a primitive value.
- Invalid attempt to destructure non-iterable instance. In…
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/f952610d5ec81bfd.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/fontawesome-free-6.7.2/js/regular.js:59
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : i + "";
}
var S = {
classic: {
fa: "solid",
fas: "solid",
"fa-solid": "solid",
far: "regular",
"fa-regular": "regular",
fal: "light",
"fa-light": "light",
fat: "thin",View on GitHub (pinned to 4306c0717f)