简体   繁体   English

NPM 工作区和 VSCode node_modules 路径

[英]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 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).当我从项目根目录执行npm i时,它会将所有包安装在根目录(node_modules)中。 It doesn't create node_modules directory in each workspace.它不会在每个工作区中创建node_modules目录。 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.因此,VSCode 认为缺少“模块” (Cannot find module 'abcde' or its corresponding type declarations) ,因此在导入行的行下显示红色并且不显示自动完成建议。

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.如何让 VSCode 了解软件包安装在根文件夹中并使用它来提供自动完成建议并删除 package 导入下的红色下划线。

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从子目录中删除package-lock.jsonnode_modules/
  2. Restart VSCode, opening it to the project's new root directory重启VSCode,打开到项目的新根目录

I think step (2) was the key to making it work, but I don't know for sure.我认为步骤 (2) 是使其工作的关键,但我不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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