Angular 和 yarn 工作区:TS 编译时缺少文件

Angular and yarn workspace : missing file at TS compilation time

上下文:我使用带有自定义 webpack/angular 5 conf 的 yarn workspace 有一段时间了。我正在尝试将 ng cli 工具与 angular 8 一起使用。但是出现了一个奇怪的问题。

首先,这里是错误:

ERROR in ../node_modules/@project/messages/src/index.ts Module build failed (from ../node_modules/@ngtools/webpack/src/index.js): Error: /path/to/right/folder/node_modules/@project/messages/src/index.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format (goo.gl/jB3GVv).

[Insert here terrible not humanly understandable stack trace]

我认为问题出在 yarn 创建的符号链接上。这是我的文件夹架构。

.
├── libs
│   ├── messages
│   │   ├── dist
│   │   ├── LICENSE
│       ├── node_modules
│   │   ├── package.json
│   │   ├── src
│   │   └── tsconfig.json
│   └── physics
│       ├── jest.config.js
│       ├── LICENSE
│       ├── node_modules
│       ├── package.json
│       ├── src
│       └── tsconfig.json
├── LICENSE
├── game
│   ├── angular.json
│   ├── browserslist
│   ├── e2e
│   ├── karma.conf.js
│   ├── LICENSE
│   ├── node_modules
│   ├── package.json
│   ├── README.md
│   ├── src
│   ├── tsconfig.app.json
│   ├── tsconfig.json
│   ├── tsconfig.spec.json
│   ├── tslint.json
│   └── yarn.lock
├── node_modules
│   ├── @project
│   └── some other packages (mb like over 99999999, but nvm)
├── package.json
├── README.md
├── server
│   ├── LICENSE
│   ├── main.ts
│   ├── node_modules
│   ├── package.json
│   ├── src
│   └── tsconfig.json
└── yarn.lock

还有符号链接映射:

ls -la node_modules/@project 
total 40
drwxrwxr-x   2 nek nek  4096 juin  24 23:24 .
drwxrwxr-x 912 nek nek 36864 juin  24 23:24 ..
lrwxrwxrwx   1 nek nek    14 juin  24 23:24 client -> ../../game
lrwxrwxrwx   1 nek nek    19 juin  24 23:24 messages -> ../../libs/messages
lrwxrwxrwx   1 nek nek    18 juin  24 23:24 physics -> ../../libs/physics
lrwxrwxrwx   1 nek nek    22 juin  24 23:24 server -> ../../server

看起来没什么不对劲。但是在构建时它失败了。我不明白为什么。但是请查看 ng --version:

的输出
$ ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 8.0.4
Node: 10.16.0
OS: linux x64
Angular: <error>
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       <error>
@angular-devkit/build-angular   <error>
@angular-devkit/core            <error>
@angular-devkit/schematics      <error>
@schematics/angular             <error>
@schematics/update              <error>
rxjs                            <error>
typescript                      <error>

它看起来有点像这个问题:https://github.com/angular/angular-cli/issues/3864#issuecomment-303168778 但我没有遇到同样的问题(考虑到 node_modules 的位置在我的情况下是准确的)。

感谢您的帮助!

我用 npm/lerna 开始了一个新项目(应该像纱线工作区一样工作)。并且有同样的问题。不过解决了。

问题出在 TypeScript 的配置上(在 tsconfig.json 文件中)。我设置了我的 tsconfig 的 path 配置:

"compilerOptions": {
    "paths": {
        "@project/physics": ["../libs/physics"]
     }
 }

像魅力一样工作。