node.js - 为什么安装一个 npm 包会在 node_modules 中添加许多子文件夹?

标签 node.js path npm dependencies

我已经更新了我在 grunt 项目中使用的 node/npm。

但是,当我现在想将包添加到项目 myproject/ 时(比如 npm install grunt-favicon),它似乎向 添加了数百个文件夹myproject/node_modules/ 而它只用于添加一个 - 通常以 grunt 为前缀,例如 node_modules/grunt-favicon

我对这些东西的了解是基本的,但这些似乎是必需的依赖项,甚至其中一些项目有更多的依赖项。

不应该在其他地方添加这些依赖项吗?如果是这样,我该如何纠正?

我使用 npm 3.3.5node 4.1.1grunt-cli v0.1.13grunt v0.4.5 .

这个截图显示左侧是 ~/.npm,右侧是 ~/myproject/node_modules

~/.npm on the left then

最佳答案

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

来自 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.

关于node.js - 为什么安装一个 npm 包会在 node_modules 中添加许多子文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32951150/

相关文章:

javascript - 父查询中每一行的子查询 - Node.js 和 node-mssql

javascript - 无法解构 `variableName` 或 'undefined' 的属性 'null'

node.js - 在 Ubuntu 20 ec2 实例中设置 Ionic 环境时出错

iOS - 查找黑色曲线包围的白色像素/区域并创建路径

javascript - 收到 package.json 的解析错误。验证为有效 json

javascript - 如何将WebRTC捕获的照片发布到服务器

python - 防止 PyCharm 扩展 sys.path

c++ - 当前路径/SDL 库

node.js - meteor EPIPE 错误中的 html-pdf

node.js - 在 npm 安装期间检测 node-webkit