OrchardCMS/OrchardCore · error · TypeError

@@toPrimitive must return a primitive value.

Error message

@@toPrimitive must return a primitive value.

What it means

Same Babel _toPrimitive helper as the conflict-detection bundle: Font Awesome's fontawesome.js throws this TypeError when a Symbol.toPrimitive implementation returns an object rather than a primitive during property-key conversion.

Solutions

  1. Fix the Symbol.toPrimitive implementation to return a primitive
  2. Remove conflicting polyfills
  3. Rebuild/refresh the Font Awesome vendor bundle to a consistent version

Example fix

// before
foo[Symbol.toPrimitive] = () => ({ });
// after
foo[Symbol.toPrimitive] = () => 'foo-key';
Defensive patterns

Strategy: type-guard

Validate before calling

function keyIsPrimitive(o) { const p = o?.[Symbol.toPrimitive]?.('string'); return p === undefined || ['string','number','symbol'].includes(typeof p); }

Type guard

function isPrimitive(v) { return v === null || ['string','number','symbol','boolean','bigint'].includes(typeof v); }

Try / catch

try { render(); } catch (e) { if (e instanceof TypeError && e.message.includes('toPrimitive')) console.error('Bad Symbol.toPrimitive return value'); }

Prevention

When it happens

Trigger: Object with a Symbol.toPrimitive returning an object passed through _toPropertyKey (e.g. used as a computed class property key) inside the transpiled Font Awesome bundle.

Common situations: Buggy polyfill overriding Symbol.toPrimitive; custom objects with invalid toPrimitive used near Font Awesome internals; mismatched transpiled helper versions in the bundle.

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


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/fecbdad5ae7b51e6. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/fontawesome-free-6.7.2/js/fontawesome.js:61

        _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 _setPrototypeOf(t, e) {
    return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
      return t.__proto__ = e, t;
    }, _setPrototypeOf(t, 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 + "";
  }
  function _wrapRegExp() {
    _wrapRegExp = function (e, r) {
      return new BabelRegExp(e, void 0, r);
    };
    var e = RegExp.prototype,
      r = new WeakMap();
    function BabelRegExp(e, t, p) {
      var o = RegExp(e, t);
      return r.set(o, p || r.get(e)), _setPrototypeOf(o, BabelRegExp.prototype);
    }
    function buildGroups(e, t) {

View on GitHub (pinned to 4306c0717f)