带有项目引用的 Typescript 构建失败,即使它已构建,“输出文件尚未从源文件构建”

Mat*_*eri 6 typescript

我正在尝试构建一个引用共享项目的项目。我的配置看起来像:

projectA/tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "lib": [
      "esnext.asynciterable"
    ],
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ],
  "references": [
    {
      "path": "../shared",
      "prepend": true
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

shared/tsconfig.json

{
  "compilerOptions": {
    "outFile": "build/out.js",
    "composite": true,
    "target": "es5",
    "module": "amd",
    "declaration": true,
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": [
    "src"
  ]
}
Run Code Online (Sandbox Code Playgroud)

ts -b从内部运行projectA产生:

src/index.ts:6:24 - error TS6305: Output file '.../shared/build/out.d.ts' has not been built from source file '.../shared/src/index.ts'.

6 import DummyClass from '../../shared/src';
Run Code Online (Sandbox Code Playgroud)

即使确实创建了此文件。

我究竟做错了什么?

Fil*_*kel 8

npx tsc -b对我来说,解决方案是在引用项目目录上运行,这需要npx告诉打字稿编译器 ( tsc) 进行构建 ( -b)。您可以将此步骤添加到您的编译管道中。

tsc -b也许更简单的方法是通过在主项目的 npm 构建脚本中运行来告诉 typescript 自行执行此操作(您可以在此处了解更多信息)。