I'm trying to set up the project using Node v14.3
and sequelize
.
I don't want to use babel-register
. Instead of this I set "type": "module"
in my package.json
and use all ES6 - ES11 features out of the box.
I also want to use sequelize-cli
for setting up and applying migrations. Everything works except the following command:
& sequelize db:migrate
Sequelize CLI [Node: 14.3.0, CLI: 5.5.1, ORM: 5.21.11]
Loaded configuration file "config/config.json".
Using environment "development".
== 20200530214311-create-user: migrating =======
ERROR: Must use import to load ES Module: /home/kasheftin/work/tests/chai-http-publication/migrations/20200530214311-create-user.js
require() of ES modules is not supported.
require() of /home/kasheftin/work/tests/chai-http-publication/migrations/20200530214311-create-user.js from /home/kasheftin/.nvm/versions/node/v14.3.0/lib/node_modules/sequelize-cli/node_modules/umzug/lib/migration.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename 20200530214311-create-user.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/kasheftin/work/tests/chai-http-publication/package.json.
We see that under the hood sequelize-cli
uses require()
. That's not allowed for ES Module. It suggests 3 ways to solve this:
rename 20200530214311-create-user.js to end in .cjs - Can not be done, sequelize-cli does not find migrations that end with .cjs.
Change the requiring code to use import() - I don't want to touch sequelize-cli code.
Remove "type": "module" - I can not because everything stops working.
Is there any other way to make sequelize-cli
work? I'm using tests heavily and I want the test database to be prepared automatically before running tests.
babel-register
mentioned in the official documentation: sequelize.org/master/manual/migrations.html. It seems this is the official way to use es6 – Comedic