[英]Paths in tsconfig not found
I have multiple project in same Angular 8 app.我在同一个 Angular 8 应用程序中有多个项目。 In "root" tsconfig.json
I add paths for @models
在“root” tsconfig.json
我为@models
添加了路径
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"],
"paths": {
"@models": ["projects/shared/models"] <=== this
}
},
I Import from index.ts
barrel I 从index.ts
桶导入
export * from "./users/user-profile.model";
export * from "./users/users.model";
When I try In any component import model from @models
当我尝试从@models
导入任何组件导入模型时
import { IUser } from "@models";
I get error我得到错误
error TS2307: Cannot find module '@models'错误 TS2307:找不到模块“@models”
But when I try to import it directly from the barrel, working ok但是当我尝试直接从桶中导入它时,工作正常
In every of my project, I also have tsconfig.app.json
, but I only add the path to the root在我的每个项目中,我也有tsconfig.app.json
,但我只将路径添加到根目录
问题出在 VS 代码中,多次重启后,一切正常
"@models": ["projects/shared/models"]
should be replaced with "@models": ["projects/shared/models/index.ts"]
in tsconfig.json file or you can write like below also "@models": ["projects/shared/models"]
应该替换为"@models": ["projects/shared/models/index.ts"]
在 tsconfig.json 文件中,或者你也可以像下面这样写
"@models": [
"projects/shared/models/*"
],
Try this尝试这个
"paths": {
"@models/*": ["projects/shared/models/*"]
}
After Updating tsconfig.json
, restart the application更新tsconfig.json
,重新启动应用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.