Mx.Wolf
Mx.Wolf

Reputation: 678

visual studio settings for typescript intellisense and TS2307 (TS) Cannot find module Miscellaneous

The command npm run build successfully build the package and the app runs in browser just fine. But the VS2019 keeps complaining with Error TS2307 (TS) Cannot find module '...'. Miscellaneous.tsconfig.json works fine

Is there a setting in the IDE where some things should be changed to make the the VS as happy as the npm?

EDIT Restart of the IDE resolved one line but not the other the IDE is still not happy

Upvotes: 4

Views: 1608

Answers (1)

Mx.Wolf
Mx.Wolf

Reputation: 678

The answer is yes. There are settings in the project that might make the experience somewhat inconsistent.

VS uses project file (.csproj) and IDE default settings to configure typescript intellisence when the tsconfig.json file is not part of the project. The npm run build command (or similar CLI approach) on the other hand uses the tsconfig.json all the time. This may lead to mixed experience. Indeed VS will show false hints and errors if particular settings differ in .csproj and in tsconfig.json.

Make sure tsconfig.json relates to the build process as Content (rather than None) yet never copied to the output directory. This way you force the IDE to detect your settings and use them.

tsconfig.json must be a part of the project

enter image description here

Upvotes: 3

Related Questions