【问题标题】:nestjs with Knex: cannot migrate and run seed in production带有 Knex 的 nestjs:无法在生产中迁移和运行种子
【发布时间】:2022-01-23 15:57:21
【问题描述】:

无法在生产环境中迁移和运行种子。 knex 尝试运行 ts 文件但失败。控制台错误:

Cannot use import statement outside a moduleD:\web-projects\product-feedback\dist\src\db\migrations\20211215210852_initial.d.ts:1
import { Knex } from 'knex';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at importFile (D:\web-projects\product-feedback\node_modules\knex\lib\migrations\util\import-file.js:12:7)
    at async D:\web-projects\product-feedback\node_modules\knex\lib\migrations\migrate\Migrator.js:87:15
    at async Promise.all (index 0)

【问题讨论】:

    标签: nestjs knex


    【解决方案1】:

    编辑您的 knex 配置选项以仅在您的生产环境中运行 .js 文件。您可以使用 loadExtensions: ['.js'] 来实现这一点,见下文:

    production: {
            client: 'pg',
            connection: pgConnection,
            pool: {
                min: 2,
                max: 10,
            },
            migrations: {
                directory: './src/db/migrations',
                loadExtensions: ['.js'],
            },
            seeds: {
                directory: './src/db/seeds',
                loadExtensions: ['.js'],
            },
        },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多