Versions
I'm submitting a ...
[x] bug report
[ ] feature request
Actual behavior:
Sequelize-typescript throwing " Model not initialized: UserModel cannot be instantiated. "UserModel" needs to be added to a Sequelize instance." exception when trying to run any queries,
The problem in model constructo: new.target is always undefined. But I can get isInitialized property from model and its set to true.
constructor(values, options) {
if (!new.target.isInitialized) {
throw new model_not_initialized_error_1.ModelNotInitializedError(new.target, `${new.target.name} cannot be instantiated.`);
}
super(values, alias_inference_service_1.inferAlias(options, new.target));
}
It works correct if I am trying to run that code without Webpack 5. Webpack 4 works correct.
Related code:
https://github.com/KAMAELUA/sequelize-typescript-webpack-error
Steps to reproduce:
ts-node works correct, so everything fine with my code:
npm run start:ts
Webpack fails:
npm run buld
npm run start
Same issue here. When downgrading to Webpack 4, it works fine.
Same here.
Anyone able to workaround it somehow?
Looking at the code output by Webpack 馃槰 :
class Model extends sequelize_1.Model {
constructor(values, options) {
if (true) { // whaaat...
throw new model_not_initialized_error_1.ModelNotInitializedError(new.target, `${new.target.name} cannot be instantiated.`);
}
super(values, alias_inference_service_1.inferAlias(options, new.target));
}
This is a bug in Webpack 5.
Reported it here - https://github.com/webpack/webpack/issues/12339
Nothing to do with this package - I think this issue can now be resolved - upgrading to the next version of Webpack when released should do the trick.
Most helpful comment
Same issue here. When downgrading to Webpack 4, it works fine.