Node v14.3我正在尝试使用and设置项目sequelize。
我不想使用babel-register. 取而代之的是,我设置"type": "module"并package.json使用所有 ES6 - ES11 开箱即用的功能。
我还想sequelize-cli用于设置和应用迁移。除以下命令外,一切正常:
& sequelize db:migrate
Sequelize CLI [Node: 14.3.0, CLI: 5.5.1, ORM: 5.21.11]
Loaded configuration file "config/config.json".
Using environment "development".
== 20200530214311-create-user: migrating =======
ERROR: Must use import to load ES Module: /home/kasheftin/work/tests/chai-http-publication/migrations/20200530214311-create-user.js
require() of ES modules is not supported.
require() of /home/kasheftin/work/tests/chai-http-publication/migrations/20200530214311-create-user.js from /home/kasheftin/.nvm/versions/node/v14.3.0/lib/node_modules/sequelize-cli/node_modules/umzug/lib/migration.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename 20200530214311-create-user.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/kasheftin/work/tests/chai-http-publication/package.json.
我们看到引擎盖下sequelize-cli使用require(). ES 模块不允许这样做。它提出了 3 种方法来解决这个问题:
将 20200530214311-create-user.js 重命名为以 .cjs 结尾 - 无法完成,sequelize-cli 找不到以 .cjs 结尾的迁移。
将需要的代码更改为使用 import() - 我不想接触 sequelize-cli 代码。
删除“类型”:“模块” - 我不能因为一切都停止工作。
有没有其他方法可以sequelize-cli工作?我正在大量使用测试,我希望在运行测试之前自动准备测试数据库。