ESM & sequelize db:migrate
See original GitHub issueIt would be great if sequelize-cli supports migrations in ESM way.
What you are doing?
// db/migrations/20220924162319-create-test.js
export async function up(queryInterface, Sequelize) {
await queryInterface.createTable('test', {
id: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true,
},
createdAt: {
allowNull: false,
type: Sequelize.DataTypes.DATE,
},
updatedAt: {
allowNull: false,
type: Sequelize.DataTypes.DATE,
}
});
}
export function down(queryInterface, Sequelize) {
return queryInterface.dropTable('test');
}
npx sequelize db:migrate
What do you expect to happen?
Migration works.
What is actually happening?
npx sequelize db:migrate
Sequelize CLI [Node: 16.16.0, CLI: 6.4.1, ORM: 6.23.0]
Loaded configuration file "db/config.js".
== 20220924162319-create-test: migrating =======
ERROR: require() of ES Module /test/db/migrations/20220924162319-create-test.js from /test/node_modules/umzug/lib/migration.js not supported.
Instead change the require of 20220924162319-create-test.js in /test/node_modules/umzug/lib/migration.js to a dynamic import() which is available in all CommonJS modules.
Output, either JSON or SQL
Dialect: postgres Database version: 12 Sequelize CLI version: 6.4.1 Sequelize version: 6.23.0
Issue Analytics
- State:
- Created a year ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
sequelize-cli-esm/README.md at master - GitHub
The Sequelize Command Line Interface (CLI) with support for EcmaScript Modules (ESM) ... as config file and db/migrate as the directory for migrations....
Read more >Using Sequelize CLI with the ESM package - Stack Overflow
Is there a way to execute Sequelize migrations with the ESM package? It requires the -r esm command line argument to be passed, ......
Read more >Migrations | Sequelize
With migrations you can transfer your existing database into another state and vice versa: Those state transitions are saved in migration ...
Read more >Can someone kindly tell me why sequelize gives this error ...
... me why sequelize gives this error while running seeders and migrations ... Ideally, you should just be using ESM import/export syntax, ...
Read more >Using Sequelize CLI with the ESM package-sequelize.js
{ "scripts": { "migrate": "node --require esm ./node_modules/.bin/sequelize-cli db:migrate" } }. then if you run npm run migrate it should work with es6 ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Indeed. We will update to the latest
umzugrelease in v7 of the CLI.As a temporary workaround to not have to rename generated migration files to .cjs, in your migrations folder, create a
package.jsonfile with contentsor, since commonjs is the default, simply