OrchardCMS/OrchardCore · error · TypeError
Cannot call a class as a function
Error message
Cannot call a class as a function
What it means
Popper's babel-compiled class guard throws this TypeError when a constructor (here Popper itself, via classCallCheck) is invoked without `new`, so `instance instanceof Constructor` is false. The ES5 transpilation of ES6 classes cannot distinguish a plain function call from construction without this runtime check.
Solutions
- Invoke the constructor with `new`: new Popper(referenceElement, popperElement, options).
- If you only need positioning for Bootstrap tooltips/dropdowns, use bootstrap's bundled Popper and remove manual Popper calls.
- Verify the imported symbol is the Popper constructor (default export of popper.js), not a helper or utils build.
- Consider upgrading to Popper 2 (@popperjs/core), which uses native ES classes and reports `Class constructor cannot be invoked without 'new'` more clearly.
Example fix
// before
var popper = Popper(referenceEl, tooltipEl, { placement: 'top' });
// after
var popper = new Popper(referenceEl, tooltipEl, { placement: 'top' }); Defensive patterns
Strategy: validation
Validate before calling
function createPopper(ref, popperEl, options) {
if (typeof Popper !== 'function') throw new Error('Popper not loaded');
return new Popper(ref, popperEl, options); // always construct with new
} Type guard
function isPopperInstance(x) { return typeof Popper === 'function' && x instanceof Popper; } Try / catch
let instance;
try {
instance = new Popper(refEl, popEl, { placement: 'bottom' });
} catch (e) {
if (e instanceof TypeError && /class as a function/.test(e.message)) {
console.error('Popper must be called with new; check import/build');
} else throw e;
} Prevention
- Always instantiate Popper with the `new` operator.
- Verify your import resolves to the Popper constructor (correct build: popper.js, not popper-utils).
- Use instanceof checks on stored Popper instances before calling methods like .scheduleUpdate().
- Consider Popper 2 (@popperjs/core) with native classes and clearer messages.
When it happens
Trigger: Calling Popper(reference, popper, options) without `new`; passing a bundled/re-exported Popper around in a way that loses construction context; calling an internal compiled class as a function after minification/concatenation mistakes.
Common situations: Old tutorial snippets or scripts using Popper 0.x/1.x API without `new`; mixing Popper builds (popper.js vs popper-utils, UMD vs ES) so the wrong export is invoked as a function; Bootstrap wiring where the Popper reference was overwritten.
Related errors
- is missing the required "orchardBaseUrl" field.
- could not find global
- 'EventSource' is not supported in your environment.
- Failed to load
- HttpConnection.stopConnection
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/750c991368116e96.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/popper-1.16.1/popper.js:375
function getSize(axis, body, html, computedStyle) {
return Math.max(body['offset' + axis], body['scroll' + axis], html['client' + axis], html['offset' + axis], html['scroll' + axis], isIE(10) ? parseInt(html['offset' + axis]) + parseInt(computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')]) + parseInt(computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')]) : 0);
}
function getWindowSizes(document) {
var body = document.body;
var html = document.documentElement;
var computedStyle = isIE(10) && getComputedStyle(html);
return {
height: getSize('Height', body, html, computedStyle),
width: getSize('Width', body, html, computedStyle)
};
}
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;View on GitHub (pinned to 4306c0717f)