Sequelize-typescript: Webpack 5 "Model not initialized" issue

Created on 3 Nov 2020  路  4Comments  路  Source: RobinBuschmann/sequelize-typescript

Versions

  • sequelize: 5.21.10
  • sequelize-typescript: 1.1.0
  • typescript: 4.0.5
  • webpack: 5.4.0

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

Most helpful comment

Same issue here. When downgrading to Webpack 4, it works fine.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zebkailash picture zebkailash  路  4Comments

thestrayed picture thestrayed  路  5Comments

ghost picture ghost  路  5Comments

samanmohamadi picture samanmohamadi  路  5Comments

lilling picture lilling  路  4Comments