NPM workspace and VSCode node_modules path

Viewed 922

I am using npm workspaces with typescript as specified in this git README https://github.com/Quramy/npm-ts-workspaces-example

When I do npm i from the project root directory it installs all packages in root directory (node_modules). It doesn't create node_modules directory in each workspace. Because of this, VSCode thinks 'module' is missing (Cannot find module 'abcde' or its corresponding type declarations), hence shows red under line on import line and doesn't show auto complete suggestion.

How can I make VSCode understand that packages are installed in root folder and use it for giving auto complete suggestion and remove red underlines under package import.

1 Answers

I had this issue when turning an existing project into a workspace of a larger project. Here are the steps that worked for me:

  1. Delete package-lock.json and node_modules/ from the subdirectory
  2. Restart VSCode, opening it to the project's new root directory

I think step (2) was the key to making it work, but I don't know for sure.

Related