Angular:tsconfig“composite”:true 标志不适用于 ng-workspace 中的库

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

我一直在努力完成这项工作,我有一个 NG16 工作区,但是每当我在

tsconfig.lib.json
中使用路径时,编辑器都不会识别这些路径,因为它不在主
tsconfig.json
中。

但是,我尝试实现新的 https://www.typescriptlang.org/docs/handbook/project-references.html 参考功能将我的 tsconfig.lib.ts 链接到我的根 tsconfig.json 但它似乎总是失败并且永远无法识别“include”模式中定义的文件。

File 'drive/x/y/z/workspace/projects/my-lib/src/lib/my-lib.module.ts' is not listed within the file list of project 'drive/x/y/z/workspaceprojects/my-lib/tsconfig.lib.prod.json'. Projects must list all files or use an 'include' pattern.

构建入口点'@workspace/my-lib

- Compiling with Angular sources in Ivy full compilation mode.
× Compiling with Angular sources in Ivy full compilation mode.
projects/my-lib/src/lib/test.service.ts:1:1 - error TS6307: File 'drive/x/y/z/workspace/projects/my-lib/src/lib/test.service.ngtypecheck.ts' is not listed within the file list of project 'drive/x/y/z/workspace/projects/my-lib/tsconfig.lib.json'. Projects must list all files or use an 'include' pattern.

1

projects/my-lib/src/public-api.ts:6:29 - error TS6307: File 'drive/x/y/z/workspace/projects/my-lib/src/lib/test.service.ts' is not listed within the file list of project 'drive/x/y/z/workspace/projects/my-lib/tsconfig.lib.json'. Projects must list all files or use an 'include' pattern.

6 export { TestService } from './lib/test.service';
`

See tsconfig.lib.json below

./projects/my-lib/tsconfig.lib.json
```
{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "outDir": "../../out-tsc/lib",
    "declaration": true,
    "declarationMap": true,
    "inlineSources": true,
    "baseUrl": "./",
    "types": [],
    "paths": { /* classified */ },
    "composite": true,
  },
  "exclude": [
    "**/*.spec.ts",
    "**/*.test.ts",
    "**/*.stories.ts",
    "**/*.stories.js",
    "**/*.stories.ts",
    "**/*.stories.js"
  ],
  "include": [
    "src/**/*.ts",
    "src/**/*.d.ts"
  ]
}
```

Root tsconfig.json
```

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "ES2022",
    "module": "ES2022",
    "useDefineForClassFields": false,

    "lib": [
      "ES2022",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  },
}

我当然期待 ng build my-lib 上的编译库,但它给出了一些我无法解决的奇怪错误。有谁知道发生了什么事吗?我已经提供了 include 属性中的所有模式

angular tsconfig
1个回答
0
投票

即使我使用 NX 生成一个新的库并尝试运行该构建,我也会遇到同样的错误。有人解决这个问题了吗?

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