当前位置:  开发笔记 > 编程语言 > 正文

当不同模块将它们用作依赖项时,如何避免相同的node.js包安装多次?

如何解决《当不同模块将它们用作依赖项时,如何避免相同的node.js包安装多次?》经验,为你挑选了1个好方法。

我注意到npm在不同模块需要它们时会多次安装相同的node.js软件包。

是否可以关闭此选项并为所有软件包提供一个回购协议?

我看了一下,但没有找到任何东西。



1> Mikhail Burs..:

This is the default behaviour of NPM since version 3. Quoting the changelog of that version:

Your dependencies will now be installed maximally flat. Insofar as is possible, all of your dependencies, and their dependencies, and THEIR dependencies will be installed in your project's node_modules folder with no nesting. You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies.

As you can see, if you have modules which have conflicting dependencies (i.e. require different versions of the same dependency), multiple versions of such dependencies will be installed, and this cannot be avoided.

如果您怀疑node_modules目录以某种方式包含重复项,则可以使用命令npm dedupe(docs)查找重复项并减少重复项,每个重复项仅保留一个实例。

推荐阅读
php
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有