繁体   English   中英

ES6 和 sequelize-cli

[英]ES6 and sequelize-cli

我的问题是如何运行用 ES6 编写的sequelize迁移/种子?

我尝试使用babel-node ,但出现奇怪的错误

命令

node_modules/babel-cli/lib/babel-node.js node_modules/sequelize-cli/bin/sequelize  db:seed

错误

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

实际上,如果我有问题,您想将 es6 与sequelize一起使用。

根据官方文档,您只需首先执行此简单步骤,安装 babel 依赖项,尤其是@babel\\register

npm install @babel\\register

其次,在项目根目录创建一个.sequelizerc ,并添加以下内容

 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')
}

完成上述操作后,您可以开始使用带有 es6 语法的 sequelize

如需进一步阅读,您可以访问官方文档http://docs.sequelizejs.com/manual/migrations.html#using-babel

记得玩得开心

试试这个配置: https : //gist.github.com/andrewmunro/030f0bf62453239c495b0347c8cd1247

它对我有用。

谷歌把我带到这里,这仍然需要配置。 但是找到了一个解决方案,它甚至可以让您使用 ES6 语法编写迁移脚本。

参考资料:https://gist.github.com/elawad/c0af86ea37629ad0538c2b974b4ea0c1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM