为什么安装一个npm软件包会在node_modules中添加许多子文件夹? [英] Why does installing one npm package add many subfolders in node_modules?

查看:1215
本文介绍了为什么安装一个npm软件包会在node_modules中添加许多子文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经更新了node / npm,我用的是grunt项目。



但是,当我现在想添加一个包到项目 myproject / (说 npm安装grunt-favicon )似乎添加了数百个文件夹到 myproject / node_modules / ,而它只用于添加一个 - 通常前缀有grunt像 node_modules / grunt-favicon



我对这些事情的了解是基本的,但这些似乎是必需的依赖关系,甚至这些项目中的一些还有更多的依赖关系。



应该不会在别的地方添加这些依赖项?如果是这样,我该如何更正?



我使用 npm 3.3.5 节点4.1.1 grunt-cli v0.1.13 grunt v0.4.5 / p>

这个截图显示在左边的〜/ .npm ,然后是〜/ myproject / node_modules 在右边



解决方案

这是正确的,别担心。您仍然在本地安装软件包,只是目录结构看起来有点不同。这是在npm v3.0.0 中更改的行为:现在所有的依赖关系都直接安装在 node_modules 文件夹中(就此而言不会导致版本冲突)。这大大减少了文件树大小。



npm 3.0.0发行说明


平,平,扁平!



您的依赖项现在将被最大程度地平坦化。在可能的情况下,所有依赖项及其依赖关系和THEIR依赖项将安装在项目的node_modules文件夹中,而不嵌套。当两个(或多个)模块具有冲突的依赖关系时,您只会看到彼此嵌套的模块。



I've updated node / npm which I use with my grunt projects.

However when I now want to add a package to a project myproject/ (say npm install grunt-favicon) it seems to add hundreds of folders to myproject/node_modules/ whereas it only used to add one - normally prefixed with grunt like node_modules/grunt-favicon.

My knowledge of these things is basic but these seem to be required dependencies, and even some of these items have even more dependencies.

Should it not be adding these dependencies somewhere else? If so how to i correct this?

I use npm 3.3.5, node 4.1.1, grunt-cli v0.1.13 and grunt v0.4.5.

And this screenshot shows ~/.npm on the left then ~/myproject/node_modules on the right

解决方案

This is correct, don't worry. You're still installing the packages locally, just the directory structure looks a bit different. It is a behaviour that changed in npm v3.0.0: now all the dependencies' dependencies are installed directly in the node_modules folder (as far as this doesn't cause version conflicts). This greatly reduces the file tree size.

From npm 3.0.0 release notes:

Flat, flat, flat!

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.

这篇关于为什么安装一个npm软件包会在node_modules中添加许多子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆