简体   繁体   中英

Short Import Typescript path mapping doesnt work in Angular 8 Project

My Angular Project Structure looks like this:

在此处输入图像描述

My goal is to be able to import the register.component.ts into the auth-routing.module.ts with

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

For that, i added the path to my tsconfig.json, which looks like this:

  "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. Does anyone have a clue whats the problem?

try change this

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

to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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