Lingua-e
JavaScript

What is a Class Extends Non-Constructor?

← Errors

This TypeError is thrown when the value after 'extends' is not a constructor function or class. JavaScript allows any expression after 'extends', so a variable holding null, undefined, or a plain object will cause this error at class definition time.

Why it happens

  • The parent class variable is null because it was not imported correctly.
  • A circular dependency causes the parent module to export undefined at the time of evaluation.
  • Extending a value returned by a factory function that returned null on failure.
  • A typo in the import name resolves to undefined.

Examples

JavaScript

Code that triggers the error

const Base = null;

class Child extends Base {
  greet() { return "hi"; }
}

Error output

TypeError: Class extends value null is not a constructor or null

How to fix it

Check that the value you are extending is a class or constructor function. Debug circular imports if the parent is undefined at evaluation time. Add a runtime assertion: if (typeof Base !== 'function') throw new Error('Base is not a constructor').

Fixed code

class Base {
  greet() { return "hello"; }
}

class Child extends Base {
  greet() { return super.greet() + " there"; }
}

Related errors

Ready to practice your English at work?

Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.

Try Lingua-e for free