无法解析tsconfig路径 [英] Cannot resolve tsconfig paths
本文介绍了无法解析tsconfig路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的TypeScript版本为"2.7.2"的Angular 6项目的tsconfig.json
为
My Angular 6 project with TypeScript version "2.7.2" has tsconfig.json
as
{
"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/*"]
}
}
我尝试使用上述路径导入服务
I tried importing a service using the above path
import { AppService } from '@services/app.service';
但是我在运行ng serve
src/app/app.module.ts(20,26)中的错误:错误TS2307:找不到模块'@ services/app.service'.
ERROR in src/app/app.module.ts(20,26): error TS2307: Cannot find module '@services/app.service'.
P.S.-没有路径
import { AppService } from './services/app.service';
工作正常.
推荐答案
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/*"]
}
},
}
这篇关于无法解析tsconfig路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文