Search code examples
jsonangulartypescriptpathtsconfig

Short Import Typescript path mapping doesnt work in Angular 8 Project


My Angular Project Structure looks like this:

enter image description here

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?


Solution

  • try change this

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

    to

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