Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In VS Code: [ts] Cannot find module '@src/xxx'

So, I'm using this tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "declaration": true,
    "module": "ES6",
    "moduleResolution": "node",
    "outDir": "./lib/",
    "paths": {
      "@src/*": ["src/*"]
    },
    "preserveConstEnums": true,
    "removeComments": true,
    "sourceMap": true,
    "target": "ES6"
  },
  "include": [
    "global.d.ts",
    "src/**/*.ts"
  ]
}

Where you can see the alias @src is defined for my code.

tsc/webpack have no problem building everything but while editing in VS Code, I can't get rid of this error message when I import something as

import { xxx } from '@src/xxx';

Anyone with the same problem? For me, it's weird to see this because if it's compiling/building properly (from tsc and webpack), it means the configuration is correct. So why VS Code is displaying this error msg? It's just annoying but I wanna solve it.

tsconfig.json file is also using the standard name (no custom -p option for tsc) so, VS Code should be able to read it automatically, right? Or any extra configuration is needed for the IDE?

like image 715
danikaze Avatar asked Jul 13 '18 07:07

danikaze


1 Answers

I had the same issue. In my case running Cmd+Shift+P > Typescript: Restart TS Server did the trick and error message disappeared

like image 181
Oleksandr Oliynyk Avatar answered Sep 24 '22 05:09

Oleksandr Oliynyk