简体   繁体   English

Angular 9 tsconfig.json & tsconfig.app.json 路径未按预期工作

[英]Angular 9 tsconfig.json & tsconfig.app.json paths are not working as expected

I have an Angular 9 project with multiple projects and one libs directory.我有一个 Angular 9 项目,其中包含多个项目和一个libs目录。 The structure is as such:结构是这样的:

- libs
- projects
   | - app1
       | - tsconfig.app.json
   | - app2
       | - tsconfig.app.json
   | - app3
       | - tsconfig.app.json
- tsconfig.json

My main tsconfig.json looks like this:我的主要tsconfig.json看起来像这样:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
      // Shared libs
      "@libs/*": ["libs/*"],

      // Projects
      "@app1/*":["projects/app1/src/app/*"],
      "@app2/*": ["projects/app2/src/app/*"],
      "@app3/*": ["projects/app3/src/app/*"]
    },
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

And each tsconfig.app.json looks like this:每个tsconfig.app.json看起来像这样:

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@modules/*": ["app/*"],
      "@core/*": ["app/core/*"],
      "@environments/*": ["environments/*"],
    },
    "outDir": "../../out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ],
  "exclude": [
    "src/test.ts",
    "src/**/*.spec.ts"
  ]
}

The issue is that in each app, the @libs path always throws Cannot find module '@libs/cool-module.module' .问题是在每个应用程序中,@ @libs路径总是抛出Cannot find module '@libs/cool-module.module' The other paths in the tsconfig.app.json are working great on compile. tsconfig.app.json中的其他路径在编译时运行良好。

NOTE: My VSCode intellisense is recognizing the @libs/... paths without an issue.注意:我的 VSCode 智能感知识别@libs/...路径没有问题。 The issue is only when compiling.问题仅在编译时出现。

What could be the issue?可能是什么问题? Thanks!谢谢!

I can find 1 difference to my tsconfig file.我可以找到我的 tsconfig 文件的 1 个不同之处。 Do you have the rootDir key implemented?您是否实施了 rootDir 密钥?

tsconfig.ts tsconfig.ts

"compilerOptions": {
    ....
    "baseUrl": ".",
    "lib": ["es2017", "dom"],
    "rootDir": "."
    ....
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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