OrchardCMS/OrchardCore · error · TypeError
@@toPrimitive must return a primitive value.
Error message
@@toPrimitive must return a primitive value.
What it means
Babel's compiled _toPrimitive helper throws this TypeError when an object defines Symbol.toPrimitive but its implementation returns an object instead of a primitive. It is bundled Font Awesome minified runtime code (conflict-detection.js), part of its ES-class shims.
Solutions
- Ensure Symbol.toPrimitive implementations return a primitive (string, number, or symbol)
- Remove/fix conflicting polyfills that redefine Symbol.toPrimitive behavior
- Verify the Font Awesome bundle version matches other bundled Babel helpers on the page
Example fix
// before
obj[Symbol.toPrimitive] = function () { return {}; };
// after
obj[Symbol.toPrimitive] = function () { return String(this.label); }; Defensive patterns
Strategy: type-guard
Validate before calling
function hasValidToPrimitive(o) { return typeof o !== 'object' || o === null || typeof o[Symbol.toPrimitive] !== 'function' || ['string','number','symbol'].includes(typeof o[Symbol.toPrimitive]('default')); } Type guard
function returnsPrimitive(v) { const r = typeof v?.[Symbol.toPrimitive] === 'function' ? v[Symbol.toPrimitive]('default') : v; return ['string','number','symbol','bigint','boolean'].includes(typeof r) || r === null; } Try / catch
try { doKeyConversion(obj); } catch (e) { if (e instanceof TypeError && e.message.includes('toPrimitive')) console.error('Symbol.toPrimitive must return a primitive', obj); } Prevention
- Never implement Symbol.toPrimitive returning objects
- Avoid polyfills that override Symbol.toPrimitive globally
- Keep vendor bundles and polyfill versions consistent
When it happens
Trigger: Calling _toPropertyKey/_toPrimitive (e.g. computed property or spread of an object) where t[Symbol.toPrimitive](hint) returns an object such as {} or an array instead of string/number/symbol.
Common situations: Malformed polyfill or monkey-patched Symbol.toPrimitive; incompatible polyfill versions on the page overriding built-ins; a custom object with a buggy toPrimitive passed where a key is expected.
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/0506942e78b488b6.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/fontawesome-free-6.7.2/js/conflict-detection.js:47
}
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 + "";
}
let _WINDOW = {};
let _DOCUMENT = {};
try {
if (typeof window !== 'undefined') _WINDOW = window;
if (typeof document !== 'undefined') _DOCUMENT = document;
} catch (e) {}
const {
userAgent = ''
} = _WINDOW.navigator || {};
const WINDOW = _WINDOW;View on GitHub (pinned to 4306c0717f)