我已经这样设置了我的角度项目:
https://angularfirebase.com/lessons/shorten-typescript-imports-in-an-angular-project/
但是它似乎没有用。 我的 tsconfig 看起来像这样:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
"module": "es2015",
"baseUrl": "./",
"paths": {
"@data/*": ["src/app/core/data/*"],
"@constants/*": ["src/app/core/constants/*"],
"@models/*": ["src/app/core/models/*"],
"@services/*": ["src/app/core/services/*", "src/app/core/sessions/*"],
"@shared/*": ["src/app/shared/*"]
}
}
}
我辛苦地遍历了整个应用程序,并用这些新路径替换了所有“长”路径,当我尝试进行ng serve
时,会遇到很多错误。
这是一对:
src / app / categories / categories.component.ts(3,31)中的错误:错误TS2307:找不到模块'@ constants / animations'。
src / app / core / components / animations / animations.component.ts(3,34):错误TS2307:找不到模块'@ constants / animations'。
src / app / core / components / animations / animations.component.ts(4,34):错误TS2307:找不到模块'@ services / animation.service'。
src / app / core / components / spinner / spinner.component.ts(3,32):错误TS2307:找不到模块'@ services / loading.service'。
有负载,当我查看实际的组件/模块时,智能感知没有显示任何问题。 有谁知道为什么会这样?
答案 0 :(得分:0)
这与 basePath 有关。应将其设置为“ src”。 因此,现在看起来像这样:
"baseUrl": "src",
"paths": {
"@data/*": ["app/core/data/*"],
"@constants/*": ["app/core/constants/*"],
"@models/*": ["app/core/models/*"],
"@services/*": ["app/core/services/*", "app/core/sessions/*"],
"@shared/*": ["app/shared/*"]
}