My question is how to run sequelize
migrations/seeds that written in ES6 ?
I tried with babel-node
, but getting weird error
Command
node_modules/babel-cli/lib/babel-node.js node_modules/sequelize-cli/bin/sequelize db:seed
Error
node_modules/babel-cli/lib/babel-node.js: line 1: /Applications: is a directory
node_modules/babel-cli/lib/babel-node.js: line 3: /Applications: is a directory
node_modules/babel-cli/lib/babel-node.js: line 4: 127.0.0.1: command not found
node_modules/babel-cli/lib/babel-node.js: line 5: syntax error near unexpected token `('
node_modules/babel-cli/lib/babel-node.js: line 5: ` * when found, before invoking the "real" _babel-node(1) executable.'
Sequelize-cli is a very useful command-line interface for creating models, configurations and migration files to databases. It's integrated with Sequelize middleware and operates with many relational databases such as PostgreSQL, MySQL, MSSQL, Sqlite.
Sequelize is a popular, easy-to-use JavaScript object relational mapping (ORM) tool that works with SQL databases.
Actually, if I got the question, you want to use es6 with sequelize
.
According to the official docs you just have to do this easy steps
firstly, Install the babel dependencies especially @babel\register
npm install @babel\register
secondly, Create a .sequelizerc
at the root of the project and add the following
require("@babel\register");
const path = require('path');
module.exports = {
'config': path.resolve('config', 'config.json'),
'models-path': path.resolve('models'),
'seeders-path': path.resolve('seeders'),
'migrations-path': path.resolve('migrations')
}
After doing the above you can start using sequelize with es6 syntax
for further reading you can visit the official docs http://docs.sequelizejs.com/manual/migrations.html#using-babel
Remember to have fun
Try this configuration: https://gist.github.com/andrewmunro/030f0bf62453239c495b0347c8cd1247.
It's working for me.
Google led me here, and this still requires configuration. But found a solution which even lets you write migrations scripts using ES6 syntax.
Reference: https://gist.github.com/elawad/c0af86ea37629ad0538c2b974b4ea0c1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With