umzug 无法在 Node js 中导入 ES 模块

问题描述 投票:0回答:1

我正在尝试使用 ExpressJS 构建一个简单的应用程序作为我的个人项目。我正在使用sequelize ORM 来处理数据库更改。现在我想回滚迁移,为此我使用了以下命令

npx sequelize-cli db:migrate:undo
当我运行上面的命令时,我遇到了以下错误。

这是我的 package.json 文件的内容。

{
  "name": "poc",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.2",
    "mysql2": "^3.6.1",
    "sequelize": "^6.33.0"
  },
  "type":"module",
  "devDependencies": {
    "sequelize-cli": "^6.6.1"
  }
}

这是我的续集迁移文件的内容。

'use strict';

/** @type {import('sequelize-cli').Migration} */

export default {
  async up (queryInterface, Sequelize) {
    /**
     * Add altering commands here.
     *
     * Example:
     * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
     */
    queryInterface.addColumn('Users','deletedAt', {
      type: Sequelize.TIME
    })
  },

  async down (queryInterface, Sequelize) {
    /**
     * Add reverting commands here.
     *
     * Example:
     * await queryInterface.dropTable('users');
     */
    queryInterface.removeColumn('Users','deletedAt')
  }
};

我想在我的项目中使用 ES6 模块和语法。 预先感谢我将收到的所有帮助。

javascript node.js ecmascript-6 sequelize.js mysql2
1个回答
0
投票

将 Sequelize 迁移文件扩展名从 .js 重命名为 .mjs

有关更多信息,我按照此处的示例进行操作(查看 .README 的内容):https://github.com/sequelize/umzug/tree/main/examples/2.es-modules

© www.soinside.com 2019 - 2024. All rights reserved.