I have an Angular 9 project with multiple projects and one libs
directory. 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:
{
"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:
{
"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'
. The other paths in the tsconfig.app.json
are working great on compile.
NOTE: My VSCode intellisense is recognizing the @libs/...
paths without an issue. The issue is only when compiling.
What could be the issue? Thanks!
I can find 1 difference to my tsconfig file. Do you have the rootDir key implemented?
tsconfig.ts
"compilerOptions": {
....
"baseUrl": ".",
"lib": ["es2017", "dom"],
"rootDir": "."
....
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.