【发布时间】:2019-12-03 12:57:19
【问题描述】:
我在 tsconfig.json 中定义的路径不起作用。
我使用 Ionic 4 开始了一个项目,并希望避免在导入中出现丑陋的路径。我找到了有关修改 tsconfig.json 的信息,我这样做了。我已经找到了这些答案: How to use paths in tsconfig.json? 和 Cannot resolve tsconfig paths
所以我的 tsconfig.json 看起来像这样:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./src",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
],
"paths": {
"@services/*": ["app/services/*"],
"@data/*": ["app/data/*"]
}
}
}
我访问了一个在我的服务中指定用户的类:
import { User } from '@data/User';
User 类如下所示:
export class User {
...
}
我的项目结构如下:
我看不出我的代码与我共享的不同解决方案有任何区别。显示的错误是:
[ng] src/app/services/profile.service.ts(3,22) 中的错误:错误 TS2307: 找不到模块“@data/User”。 [ng]
我做错了什么?
【问题讨论】:
-
你重新启动服务器了吗?
-
就是这样,谢谢。
标签: angular typescript ionic-framework ecmascript-6 single-page-application