tsconfig.app.json 的别名不起作用 Angular 11
Aliasing for tsconfig.app.json not working Angular 11
自从我将我的应用移至 angular 项目
后,我在使用别名时遇到了问题
None 我的导入使用我的“@app”别名
mainApp
│ package.json
│ tsconfig.json
│ angular.json
│
└───projects
│
└───my-project (That I need the aliasing for)
│ tsconfig.app.json
│
└───src
│
└───app
当我使用:
import { MyService } from '@app/shared/services/my.service';
我遇到错误
在我的 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"
]
}
我试过了
"@app/*": ["projects/my-project/src/app/*"],
我也更新了我的主tsconfig.json:
....
"baseUrl": "./",
"paths": {
"@app/*": ["src/app/*"],
"@env/*": ["environments/*"]
},
...
然后服务项目:
ng serve --project my-project
问题是因为我的路径对象在 compilerOptions
对象之外,所以:
"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"
]
}
成功了!!!
而不是
"compilerOptions": {
.......
},"paths": {
"@app/*": ["projects/my-project/src/app/*"],
"@env/*": ["environments/*"]
}
自从我将我的应用移至 angular 项目
后,我在使用别名时遇到了问题None 我的导入使用我的“@app”别名
mainApp
│ package.json
│ tsconfig.json
│ angular.json
│
└───projects
│
└───my-project (That I need the aliasing for)
│ tsconfig.app.json
│
└───src
│
└───app
当我使用:
import { MyService } from '@app/shared/services/my.service';
我遇到错误
在我的 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"
]
}
我试过了
"@app/*": ["projects/my-project/src/app/*"],
我也更新了我的主tsconfig.json:
....
"baseUrl": "./",
"paths": {
"@app/*": ["src/app/*"],
"@env/*": ["environments/*"]
},
...
然后服务项目:
ng serve --project my-project
问题是因为我的路径对象在 compilerOptions
对象之外,所以:
"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"
]
}
成功了!!! 而不是
"compilerOptions": {
.......
},"paths": {
"@app/*": ["projects/my-project/src/app/*"],
"@env/*": ["environments/*"]
}