'ES6 and sequelize-cli
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.'
Solution 1:[1]
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
Solution 2:[2]
Try this configuration: https://gist.github.com/andrewmunro/030f0bf62453239c495b0347c8cd1247.
It's working for me.
Solution 3:[3]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Mikhail Bobrovsky |
| Solution 3 | Aymen |
