我的TypeScript版本为“ 2.7.2”的Angular 6项目的tsconfig.json
为
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
},
"paths":{
"@services/*": ["app/services/*"]
}
}
我尝试使用上述路径导入服务
import { AppService } from '@services/app.service';
但是我在运行ng serve
时遇到此错误
src / app / app.module.ts(20,26)中的错误:错误TS2307:找不到模块'@ services / app.service'。
P.S。-没有路径
import { AppService } from './services/app.service';
工作正常。
答案 0 :(得分:3)
paths
选项是compilerOptions
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
"paths":{
"@services/*": ["app/services/*"]
}
},
}