简体   繁体   中英

nestjs with Knex: cannot migrate and run seed in production

cannot migrate and run seed in production. The knex tries to run a ts file and it fails. Console error:

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)

Edit your knex config options to only run.js files in your production. You can achieve this with loadExtensions: ['.js'], see bellow:

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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