cli: models/index.js doesn't work with ES6 modules
What you are doing?
Trying to load models with models/index.js doesn’t work with ES6 modules activated with "type": "module"
const basename = path.basename(__filename);
// {...}
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
Variables like __filename
and __dirname
don’t work anymore with modules.
What do you expect to happen?
There should be an option to choose between Modules or CommonJS.
What is actually happening?
There’s only CommonJS support.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 21 (5 by maintainers)
This is my solution for the moment
For now, I created this temporary solution.
Thanks a lot for your effort. I tried it out and can confirm that it works. Unfortunately I ran into another issue: migrations seem not to work with ES6 modules out of the box. Possible solutions seem quite hacky. I decided to keep using CommonJS syntax and wait until there is better support for ES6.
I write like this but it is’nt load the models and then give my the error: TypeError: model.default is not a function
how can i fix it?