简体   繁体   中英

NPM workspace and VSCode node_modules path

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM