我正在做一个 Angular 项目。我有一个图书馆tools
和一个项目example
。我的项目结构看起来像这样(Monorepo)
root
|-- projects
| |-- example
| | |-- src
| | | `-- app
| | | |-- app.module.ts
| | | `-- view
| | | `-- main.component.ts
| | `-- tsconfig.app.json
| `-- tools
`-- tsconfig.json
我的tsconfig.json
长相是这样的
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": false,
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
}
}
和我的tsconfig.app.json
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": [],
"allowJs": true,
"experimentalDecorators": true,
"traceResolution": true,
"paths": {
"tools": [
"dist/tools/tools",
"dist/tools"
],
"@example/*": [
"projects/example/src/app/*",
"projects/example/src/app/view/features/*",
"projects/example/src/app/core/guards/index.ts",
"projects/example/src/app/core/components/index.ts",
"projects/example/src/app/core/model/index.ts",
"projects/example/src/app/core/services/index.ts",
"projects/example/src/app/view/features/f1/store/index.ts",
"projects/example/src/app/view/features/f2/store/index.ts",
"projects/example/src/app/view/features/f3/store/index.ts"
]
}
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
当我尝试导入tools
myapp.module.ts
时,它工作正常。但是当我在任何功能/子模块中导入它时,例如main.component.ts
,IntelliJ 将其标记为错误。
TS2307: Cannot find module 'tools' or its corresponding type declarations
我尝试tsc --project projects/example/tsconfig.app.json
在命令行中运行并检查输出,我发现它已成功解决
Module name 'tools' was successfully resolved
我一无所知,没有解决方案!