本文介绍了如何防止 npm install 删除软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个包含多个包的开发环境,因此我需要手动安装一些依赖项.更具体地说,我需要在几个包中进行一些本地更改,然后才能将它们推送到 github,所以我不能只是 npm install 顶级,因为它不会选择那些改变.所以我在缺少的包上手动运行第一个 npm install,然后尝试运行我的节点代码并查看它仍然缺少哪个包,然后尝试 npm install它说的东西不见了.

I'm trying to set up a development environment with several packages, and as a result I need to manually install some dependencies. More specifically, I have some local changes in several packages which I need to test before I can push them to github, so I can't just npm install the top level because it won't pick up those change. So I run the first npm install manually on packages which are missing, and then try to run my node code and see which package it is still missing, then try to npm install what it says is missing.

然而,当我去安装第二个包时,它以这样的消息结束:

However, when I go to install the second package, it ends up with this message:

added 3 packages from 4 contributors, removed 799 packages and audited 3 packages in 4.197s

第二次安装几乎删除了所有已经安装的包!直到第三次我才注意到这一点,当时我意识到我似乎一遍又一遍地安装相同的东西.

The second install removed practically every package that was already installed! I didn't notice this until about the third time, when I realized that I seemed to be installing the same thing over and over.

但是,我可以防止这种特别顽皮的行为并强制 npm 只安装我告诉它的内容,而不管其他一切吗?

However can I prevent this particularly naughty behavior and force npm to only install what I tell it to and leave everything else alone?

推荐答案

如果您需要针对修改后的包进行测试,请查看 npm link.

Have a look at npm link if you need to test against modified packages.

来自 npm 链接:这对于安装您自己的东西很方便,这样您就可以对其进行处理和迭代测试,而无需不断地重新构建.

ba 的依赖.您对 b 进行了更改,并想检查 a 是否仍然适用于这些更改.不要在从 npm 安装的 node_modules 中使用 b,而是使用您的本地修改版本:

Say b is a dependency of a. You made changes to b and want to check if a still works with those changes. Instead of using b in node_modules installed from npm, use your local, modified version:

cd ~/projects/b    # go into the package directory
npm link           # creates global link
cd ~/projects/a    # go into some other package directory.
npm link b         # link-install the package

现在,对 ~/projects/b 的任何更改都将反映在 ~/projects/a/node_modules/b/ 中.

Now, any changes to ~/projects/b will be reflected in ~/projects/a/node_modules/b/.

这篇关于如何防止 npm install 删除软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:07