【问题标题】:Knexfile Not Using TS PathsKnexfile 不使用 TS 路径
【发布时间】:2022-11-05 18:52:40
【问题描述】:

我正在尝试运行迁移。我的 Knexfile 是用 Typescript 编写的,其中一些路径别名来自 tsonfig.json,但 Knex 以 Cannot find module '@foo-alias/bar-module' 失败。我需要在运行 Knex migrate 的方式或我的 TS 配置中进行哪些更改才能使其正常工作?

根据我在网上看到的一些线程,我尝试过使用这样的东西,但没有骰子:

TS_NODE_PROJECT=tsconfig.knexfile.json knex migrate:latest

{
  "compilerOptions": {
    ...a bunch of compiler options here
    "paths": {
      "@foo-alias/*": ["src/foo/*"]
    }
  },
  "exclude": ["node_modules"]
}

【问题讨论】:

    标签: node.js typescript database-migration knex.js npm-scripts


    【解决方案1】:

    我只需要像这样注册tsconfig 路径:

    ts-node -r tsconfig-paths/register ./node_modules/.bin/knex --knexfile ./knexfile.ts "migrate:latest"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-15
      • 2019-01-05
      • 2021-09-15
      • 2022-06-20
      • 2021-11-16
      • 1970-01-01
      • 2017-07-04
      • 2019-07-12
      相关资源
      最近更新 更多