X is not a constructor
JavaScript Programming Language
Severity: ModerateWhat Does This Error Mean?
The JavaScript error 'X is not a constructor' means you used the new keyword on something that cannot be used as a constructor to create objects. Only functions and classes can be called with new. If you try to use new on an arrow function, a regular object, a null value, or an imported value that is not a class or function, JavaScript throws this error. The fix is to check what you are calling with new and make sure it is actually a class or a regular function.
Affected Models
- All browsers
- Node.js
- All JavaScript environments
Common Causes
- Using new on an arrow function — arrow functions cannot be constructors
- The variable you are calling with new is undefined because of a missing or failed import
- The module you imported exports a plain object or a value, not a class or constructor function
- Using new on a built-in that is not a constructor, like new Math() or new JSON()
- A typo in the constructor name means JavaScript found an undefined variable instead of your class
How to Fix It
-
Check what you are passing to new. Add console.log(YourThing) right before the line that fails. If it logs undefined, null, or an object, that is your problem.
Knowing the actual value at runtime is the fastest way to diagnose this. You may think you imported a class but actually imported something else.
-
If the error involves an arrow function, convert it to a regular function or a class. Arrow functions use the syntax: const fn = () => {} and cannot be used with new. Use function fn() {} or class Fn {} instead.
Arrow functions were intentionally designed without a prototype and cannot create instances. This is a feature, not a bug — use a regular function or class for anything you need to instantiate with new.
-
Check your import statement. Make sure you are importing the class itself, not the module's default export wrapper or a named property. Compare: import MyClass from './my-class' versus import { MyClass } from './my-class'.
A wrong import syntax can give you an object or module namespace instead of the class, which then fails when you try to use new on it.
-
If you are using a library, check the library's documentation for the correct way to instantiate it. Some libraries export factory functions (call them without new) rather than classes (use new).
Not all libraries follow the same pattern. Some use MyLib.create() instead of new MyLib(). The library's README or API docs will show the correct usage.
-
Check for typos in the constructor name. JavaScript is case-sensitive — myClass and MyClass are different. A typo means the variable is undefined, and undefined is not a constructor.
This is a very common cause. Double-check the spelling and capitalization of your class or constructor function name.
When to Call a Professional
This is a fixable code error with no need for outside help. The error message tells you the name of the thing that is not a constructor. Start by checking what that variable actually contains using console.log before the new call.
Frequently Asked Questions
Why can arrow functions not be used as constructors?
Arrow functions do not have their own this binding and do not have a prototype property. Constructors need both of these things to create new objects and set up inheritance. This was a deliberate design decision in ES6 — arrow functions are lightweight and meant for short callbacks, not for creating instances.
I am using new Date() and it works fine, but new Math() fails. Why?
Date is a constructor — it is designed to create Date objects with new. Math is a plain built-in object (a namespace) that holds math functions. It is not a constructor and was never meant to be used with new. Use Math.random(), Math.floor() etc. directly — no new required.
The error says 'undefined is not a constructor'. What does that mean?
It means the variable you called with new is undefined — it holds no value. The most common cause is a failed or incorrectly written import. Check that the file you are importing from exists, that you are using the correct named or default export syntax, and that there are no typos in the import path.