Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在tsconfig中找不到路径_Angular_Typescript - Fatal编程技术网

Angular 在tsconfig中找不到路径

Angular 在tsconfig中找不到路径,angular,typescript,Angular,Typescript,我在同一个Angular 8应用程序中有多个项目。 在“root”tsconfig.json中,我为@models "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "downlevelIteration": true, "experimentalDecorators": true,

我在同一个Angular 8应用程序中有多个项目。 在“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
    }
  },
import { IUser } from "@models";
当我尝试从
@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
    }
  },
import { IUser } from "@models";
我犯了一个错误

错误TS2307:找不到模块'@models'

但是当我试着直接从桶中导入时,工作正常

在我的每个项目中,我也有
tsconfig.app.json
,但我只添加了根目录的路径

“@models”:[“projects/shared/models”]
应该替换为tsconfig.json文件中的
“@models”:[“projects/shared/models/index.ts”]
,或者你也可以这样写

  "@models": [
    "projects/shared/models/*"
  ],

问题出现在VS代码中,在多次重新启动后,一切正常

"paths": {
      "@models/*": ["projects/shared/models/*"]
    }

更新
tsconfig.json
后,重新启动应用程序

“@models”:[“projects/shared/models”]
应替换为
“@models”:[“projects/shared/models/index.ts”]
在tsconfig.json文件中,你能共享stackblitz链接以供进一步调查吗?我会尝试,但这是一个非常大的应用程序,我试着举个例子,你能分享tsconfig.app.json吗。请检查tsconfig.app.json中设置的基本url是什么,也就是tsconfig.app.json{“扩展”:“../../tsconfig.json”,“编译器选项”:{“outDir”:“../../out tsc/app”,“类型”:[]},“文件”:[“src/main.ts”,“src/polyfills.ts”],“包括”:[“src/***.ts”],“排除”:[“src/test.ts”,“src/***.spec ts”]我试过在我的地方,它的工作。请尝试重新启动编辑器。