Reputation: 3936
I have a simple application that is imported from webpack. The imported project exports a class like this...
export class BaseApp{...}
import { BaseApp } from "./MyClass"
import OtherThing from "./Other"
....
export { BaseApp, OtherThing }
Next I try to extend it in another node/express project...
import { BaseApp } from "@mine/util";
export class FullApp extends BaseApp{... }
I get...
class FullApp extends _mine_util__WEBPACK_IMPORTED_MODULE_0__["BaseA
pp"]{
^
TypeError: Class extends value undefined is not a constructor or null
How do I extend a class I am importing from Webpack?
Update here is an example project that demonstrates the issue...
https://github.com/jrgleason/simple-webpack-node
Upvotes: 5
Views: 14730
Reputation: 2524
Impossible to say for certain when there is clearly much more to the source. If anyone else sees this error, the first thing to look for is circular dependencies: a file depends on some other file that (likely indirectly) depends on the first. JS must start somewhere, will not be able to ensure that a file is defined at the time that another file needs it, and will not try to go back and fill in the blanks later.
If you have more than a couple import / require statements, I recommend periodically running a checker like Madge to find and optionally visualize any loops before they become hard to undo.
npm i --saveDev madge
node node_modules/madge/bin/cli.js --warning --circular --extensions js ./
Upvotes: 12