简体   繁体   English

短导入 Typescript 路径映射在 Angular 8 项目中不起作用

[英]Short Import Typescript path mapping doesnt work in Angular 8 Project

My Angular Project Structure looks like this:我的 Angular 项目结构如下所示:

在此处输入图像描述

My goal is to be able to import the register.component.ts into the auth-routing.module.ts with我的目标是能够将 register.component.ts 导入到 auth-routing.module.ts 中

import { RegisterComponent } from '@pages/auth/authpages/register/register.component';

For that, i added the path to my tsconfig.json, which looks like this:为此,我将路径添加到我的 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
  }
}

For some reason, it still does not work.由于某种原因,它仍然无法正常工作。 The component is properly exported and can be targeted with standard ts paths.该组件已正确导出,并且可以使用标准 ts 路径作为目标。 Does anyone have a clue whats the problem?有谁知道问题出在哪里?

try change this尝试改变这个

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

to

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM