简体   繁体   English

为什么 npm 安装不安装包到 /node_modules 文件夹?

[英]Why is npm install not installing packages into /node_modules folder?

When I npm install package, npm says that it successfully installed the package, but when I look for it in the node_modules folder, the package is not in the folder. When I npm install package, npm says that it successfully installed the package, but when I look for it in the node_modules folder, the package is not in the folder. When I npm install -g package, the package gets installed into the global /node_modules folder, so I have to drag the package from the global folder to the local folder. When I npm install -g package, the package gets installed into the global /node_modules folder, so I have to drag the package from the global folder to the local folder.

Why is npm install not installing into my local /node_modules folder?为什么 npm 安装没有安装到我的本地 /node_modules 文件夹中?

There are a few things you can do to resolve this problem, as mentioned here .here所述,您可以采取一些措施来解决此问题。

First, try deleting your package-lock.json file.首先,尝试删除您的package-lock.json文件。 If you run npm install or npm i after that it should generate a brand new installation with no reference to an existing package-lock.json file.如果您运行npm installnpm i之后,它应该生成一个全新的安装,而不参考现有的package-lock.json文件。

If that doesn't work, try deleting your node_modules directory in your project.如果这不起作用,请尝试删除项目中的node_modules目录。 Then run npm install or npm i .然后运行npm installnpm i

If THAT doesn't work, you should try deleting both the node_modules directory AND the package-lock.json .如果这不起作用,您应该尝试删除node_modules目录和package-lock.json Then run npm install or npm i .然后运行npm installnpm i This should resolve the issue.这应该可以解决问题。

step 1) rm -rf./node_modules from your root directory.步骤 1) rm -rf./node_modules从您的根目录。

step 2) npm install .步骤 2) npm install

The above commands first deletes your node_modules and then reinstalls all the packages that are found inside your package.json.上述命令首先删除您的 node_modules,然后重新安装在 package.json 中找到的所有包。

This is the same problem I was facing, both the above commands resolved the problem in my case.这是我面临的同样问题,上述两个命令都解决了我的问题。

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

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