最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ES6 and sequelize-cli - Stack Overflow

programmeradmin0浏览0评论

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.'

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.'
Share Improve this question asked Apr 14, 2016 at 19:55 Dima VergunovDima Vergunov 2011 gold badge3 silver badges9 bronze badges 1
  • Can you provide example of your ES6 migrations/seeds? – Eddie Jaoude Commented Sep 13, 2016 at 10:02
Add a comment  | 

3 Answers 3

Reset to default 9

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

发布评论

评论列表(0)

  1. 暂无评论