Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.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
Json 短导入类型脚本路径映射在Angular 8项目中不起作用_Json_Angular_Typescript_Path_Tsconfig - Fatal编程技术网

Json 短导入类型脚本路径映射在Angular 8项目中不起作用

Json 短导入类型脚本路径映射在Angular 8项目中不起作用,json,angular,typescript,path,tsconfig,Json,Angular,Typescript,Path,Tsconfig,我的角度项目结构如下所示: "compileOnSave": false, "compilerOptions": { "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "downlevelIteration": true, "experimentalDecorators": true, "module": "esnext", "moduleRes

我的角度项目结构如下所示:

  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "typeRoots": ["node_modules/@types"],
    "importHelpers": true,
    "target": "es2015",
    "lib": [
      "es2018",
      "dom"
    ],
    "baseUrl": "src",
    "paths": {

      "@pages/*": ["app/pages*"]
    }
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}
我的目标是能够使用将register.component.ts导入auth-routing.module.ts

import { RegisterComponent } from '@pages/auth/authpages/register/register.component';
为此,我添加了tsconfig.json的路径,如下所示:

  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "typeRoots": ["node_modules/@types"],
    "importHelpers": true,
    "target": "es2015",
    "lib": [
      "es2018",
      "dom"
    ],
    "baseUrl": "src",
    "paths": {

      "@pages/*": ["app/pages*"]
    }
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}
由于某种原因,它仍然不起作用。 组件已正确导出,并且可以使用标准ts路径作为目标。 有人知道问题出在哪里吗?

试试改变这个

"@pages/*": ["app/pages*"] 


你有什么错误?你能检查一下baseUrl:./src和@pages/*:[./app/pages/*]是否有区别吗?也许仅仅@pages/*:[app/pages/*]就可以完成这项工作。它只是说无法从路径中找到模块,建议的代码没有改变任何东西。解决方案部分起作用,现在错误已在vs代码中消失,但在运行应用程序时,它会在控制台中打印相同的错误。无法在src/app/pages/auth/auth routing.module.ts:4:35中获取whyERROR-错误TS2307:找不到模块'@pages/auth/authpages/register/register.component'.hmmm。。。。奇怪,我试着在我的本地电脑上设置它。重新运行应用程序也一样吗?还是一样,可能是因为路由/auth/register设置为延迟加载。但是它的意思是vs代码说没有错误,节点说错误。我找到了一种方法来解决这个问题,我在tsconfig.spec和tsconfig.app中将baseURL更改为../src。以前只是。/现在vs代码对此不满意,并将这三个文件标记为问题,但应用程序编译时没有错误。也许你有办法解决这个问题?如果不是,我仍然会接受你的解决方案