[英]Aliasing for tsconfig.app.json not working Angular 11
I'm having an issue getting aliasing to work since I've moved my app into an angular project自从我将应用程序移入 angular 项目后,我在使用别名时遇到问题
None of my imports work with my "@app" alias我的所有导入都不适用于我的“@app”别名
mainApp
│ package.json
│ tsconfig.json
│ angular.json
│
└───projects
│
└───my-project (That I need the aliasing for)
│ tsconfig.app.json
│
└───src
│
└───app
When I use:当我使用:
import { MyService } from '@app/shared/services/my.service';
I get errors我收到错误
In my tsconfig.app.json:在我的 tsconfig.app.json 中:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": []
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"baseUrl": "./",
"paths": {
"@app/*": ["src/app/*"],
"@env/*": ["environments/*"]
},
"include": [
"src/**/*.d.ts"
]
}
I've tried我试过了
"@app/*": ["projects/my-project/src/app/*"],
I also updated my main tsconfig.json:我还更新了我的主要 tsconfig.json:
....
"baseUrl": "./",
"paths": {
"@app/*": ["src/app/*"],
"@env/*": ["environments/*"]
},
...
And then serve the project:然后为项目服务:
ng serve --project my-project
The issue was because my paths object was outside of the compilerOptions
object, so:问题是因为我的路径 object 在compilerOptions
object 之外,所以:
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@app/*": ["projects/my-/src/app/*"],
"@env/*": ["environments/*"]
},
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
}
worked!!!工作! Rather than而不是
"compilerOptions": {
.......
},"paths": {
"@app/*": ["projects/my-project/src/app/*"],
"@env/*": ["environments/*"]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.