How to Fix “is not a constructor” in JavaScript
TypeError: Counter is not a constructor appears when new is called on a value that is neither a class nor a regular function. It shows up when you create an instance with new from a class you wrote, or from a class imported from another file. This article covers two cases: calling new on an arrow function, which cannot be used as a constructor, and importing a module with the wrong form (default export vs. named export), which gives you an object that holds the class, or undefined.
In my test environment, I triggered this error both in the browser console and in the Node.js terminal, and copied the messages exactly as they were printed. In every case, after the fix the error went away and the counter value was displayed.
The test environment was Ubuntu 24.04 and Node.js 22.23.4. For the browser, I used Chromium 153 launched headless with Playwright 1.63.0, and served the page with Python 3.11's http.server. I took the console messages from the DevTools protocol and also captured screenshots of the DevTools panel. I did not test Firefox or Safari, nor did I test through tools such as Vite or webpack, or TypeScript.
Calling new on an arrow function
The page I used in the browser test contained only a paragraph <p id="out">Preparing…</p> to display the result, and <script type="module" src="main.js">. In main.js, I wrote the function that creates the counter as an arrow function and called it with new.
const out = document.getElementById('out');
const Counter = (start) => {
this.count = start;
};
const counter = new Counter(0);
out.textContent = `count: ${counter.count}`;
When I opened the page, the screen stayed at "Preparing…" and the DevTools Console panel showed the following.
Uncaught TypeError: Counter is not a constructor
at main.js:7:17
The main.js:7:17 on the second line points to line 7, column 17 of main.js, which is the new in new Counter(0).
For Node.js, I prepared counter.js with the browser-only document lines removed and the display changed to console.log.
const Counter = (start) => {
this.count = start;
};
const counter = new Counter(0);
console.log(`count: ${counter.count}`);
Running node counter.js printed the following in the terminal, and the exit code was 1. (The file path is replaced with /path/to/app.)
/path/to/app/counter.js:5
const counter = new Counter(0);
^
TypeError: Counter is not a constructor
at Object.<anonymous> (/path/to/app/counter.js:5:17)
at Module._compile (node:internal/modules/cjs/loader:1781:14)
at Object..js (node:internal/modules/cjs/loader:1913:10)
at Module.load (node:internal/modules/cjs/loader:1505:32)
at Function._load (node:internal/modules/cjs/loader:1309:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:254:19)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
at node:internal/main/run_main_module:36:49
Node.js v22.23.4
In Node.js, the line that caused the error is printed as is, and the ^ points to the new. Lines containing node:internal/ are Node.js's internal processing. Look at the line that shows your own file name (here, counter.js:5:17) to find where the error is.
The MDN explanation of arrow functions states that arrow functions cannot be used as constructors and that calling them with new throws a TypeError. To fix it, rewrite the code using class.
class Counter {
constructor(start) {
this.count = start;
}
}
With this, no error occurred, and both the browser screen and the Node.js terminal showed count: 0. When I wrote it with function, as in function Counter(start) { this.count = start; }, the browser also raised no error and showed count: 0.
Calling new on a value imported with import * as
From here, the class itself is written correctly, but the import form is wrong. In counter.js, the class is a default export.
export default class Counter {
constructor(start) {
this.count = start;
}
increment() {
this.count += 1;
return this.count;
}
}
I imported it in main.js with import * as Counter and called it with new.
import * as Counter from './counter.js';
const out = document.getElementById('out');
const counter = new Counter(0);
counter.increment();
out.textContent = `count: ${counter.count}`;
The Console panel showed Uncaught TypeError: Counter is not a constructor. The location was main.js:4:17, which points to the new on line 4.

import * as gives you not the class itself but an object that collects everything the file exports. The MDN explanation of import calls this a module namespace object and states that the default export is stored inside it under the name default. To confirm, I replaced the new line with console.log(Counter) and console.log(typeof Counter). The Console panel showed the following.

typeof returns object, and the class (shown as ƒ) is inside as default. As described in the default import section of the MDN import explanation, when you import a default export you write it without braces or * as. When I changed the first line to the following, no error occurred and the screen showed count: 1.
import Counter from './counter.js';
import { Counter } gives a different error
Conversely, when I imported the default-exported class with a named import, import { Counter } from './counter.js', I did not get the is not a constructor error. Instead, the error occurred at import time, before reaching new.
Uncaught SyntaxError: The requested module './counter.js' does not provide an export named 'Counter' (at main.js:1:10)
In my browser test, loading the module directly, the mistake of importing a default export by name showed up as this does not provide an export named error, not as is not a constructor.
Calling new on a value imported with import()
The same mistake happens with dynamic import(). What import() returns is also the object, not the class.
const out = document.getElementById('out');
const Counter = await import('./counter.js');
const counter = new Counter(0);
The Console panel showed Uncaught TypeError: Counter is not a constructor (at main.js:4:17). As described in the MDN explanation of import(), you take out default with destructuring and give it a name. When I changed line 3 to the following, no error occurred and the screen showed count: 1.
const { default: Counter } = await import('./counter.js');
Mixing up require in Node.js
In Node.js CommonJS (require and module.exports), mixing up the import form produces the same error. require() returns the value you put in the other file's module.exports (the code in the Node.js CommonJS modules documentation that shows how require() works also returns module.exports at the end).
At the end of counter.js, I put the class into an object with module.exports = { Counter };, and in main.js I received the whole object and called it with new.
const Counter = require('./counter.js');
const counter = new Counter(0);
Running node main.js printed TypeError: Counter is not a constructor in the terminal (at main.js:3:17, exit code 1). Logging the result of require with console.log gave { Counter: [class Counter] }, so the class is inside the object. When I changed the receiving side to destructuring, no error occurred and the screen showed count: 1.
const { Counter } = require('./counter.js');
The reverse mistake produced the same message. counter.js put the class itself in with module.exports = Counter;, but when I received it with destructuring, const { Counter } = require('./counter.js');, console.log(Counter) printed undefined, because the class has no property named Counter. Calling new on this value again gave TypeError: Counter is not a constructor, and the word undefined did not appear in the message. Changing it back to const Counter = require('./counter.js'); removed the error and showed count: 1.
The message was the same Counter is not a constructor whether the value passed to new was an object or undefined. To find out which one it is, put console.log(Counter) just before the new.
Importing a CommonJS file from ES Modules
I also tested a .mjs file (ES Modules) that imported counter.cjs, which contained module.exports = { Counter };, with import Counter from './counter.cjs';, and called it with new. Running node main.mjs printed the following. (The file path is replaced with /path/to/app.)
file:///path/to/app/main.mjs:3
const counter = new Counter(0);
^
TypeError: Counter is not a constructor
at file:///path/to/app/main.mjs:3:17
at ModuleJob.run (node:internal/modules/esm/module_job:343:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:681:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
Node.js v22.23.4
The Node.js ES Modules documentation states that when a CommonJS file is loaded with a default import, the value of module.exports is used as is. In this example, module.exports is an object, so Counter held { Counter: [class Counter] }. The result of console.log was the same as with require.
The same documentation says that Node.js statically analyzes CommonJS files and makes the named exports it can detect available to named imports. In my test environment, when I changed the first line to a named import as shown below, no error occurred and the screen showed count: 1.
import { Counter } from './counter.cjs';
Summary of import forms and fixes
Here is a summary of the combinations I tested that produced the error, and the fixes.
| How the other file is written | Import form that produced the error | Import form that fixed it |
|---|---|---|
export default class Counter |
import * as Counter from |
import Counter from |
export default class Counter |
const Counter = await import(...) |
const { default: Counter } = await import(...) |
module.exports = { Counter } |
const Counter = require(...) |
const { Counter } = require(...) |
module.exports = Counter |
const { Counter } = require(...) |
const Counter = require(...) |
module.exports = { Counter } (.cjs) |
import Counter from (from .mjs) |
import { Counter } from |
According to the MDN explanation of the "is not a constructor" error, this message uses the same wording in V8-based environments such as Chromium, as well as in Firefox and Safari. The page also says it appears when new is called on built-in objects that cannot be constructed, such as Math and JSON, or on generator functions.





