5

I am having an issue where my path aliases (e.g.- import * as fromUsers from '@store/user/user.reducer';) are not being recognized within VS Code. (Note- on compiling everything works fine). VS Code reports "Cannot find module '@store/user/user.reducer'"

I have both a <root>/tsconfig.json, and a <root>/src/tsconfig.spec.json which look like:

tsconfig.json

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["dom", "es2015"],
    "baseUrl": "./src",
    "paths": {
      "@store/*": ["app/store/*"],
      "@core/*": ["app/core/*"],
      "@components/*": ["app/components/*"],
      "@app/*": ["app/*"],
      "@assets/*": ["assets/*"],
      "@env": ["environments/environment"],
      "@pages/*": ["pages/*"],
      "@theme/*": ["theme/*"]
    },
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5"
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules", "src/**/*.spec.ts", "src/**/__tests__/*.ts"],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  },
  "types": ["jasmine"]
}

and src/tsconfig.spec.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "baseUrl": ".",
    "module": "commonjs",
    "target": "es5",
    "allowJs": true,
    "paths": {
      "@store/*": ["app/store/*"],
      "@core/*": ["app/core/*"],
      "@components/*": ["app/components/*"],
      "@app/*": ["app/*"],
      "@assets/*": ["assets/*"],
      "@env": ["environments/environment"],
      "@pages/*": ["pages/*"],
      "@theme/*": ["theme/*"]
    }
  },
  "include": ["**/*.spec.ts"],
  "exclude": ["node_modules"]
}

Any thoughts on how I can get VS Code to recognize those aliases, so that I dont keep seeing errors being reported in the IDE?

MarkD
  • 4,864
  • 5
  • 36
  • 67
  • Take a look at [this](https://stackoverflow.com/questions/50593774/cannot-find-typescript-module-even-though-tsc-successfully-manages-to-resolve-it/50633528#50633528) question. I don't have enough details about your setup, but it might be the case that you are experiencing a similar issue. Good luck! – edu_ Jun 02 '18 at 01:04
  • Did you find an answer? – maxpaj Apr 10 '19 at 09:05

0 Answers0