npm 以一种奇怪的递归方式安装依赖项 [英] npm is installing dependencies in a weird recursive way

查看:94
本文介绍了npm 以一种奇怪的递归方式安装依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 npm install --dev 来安装 package.json 文件中列出的依赖项,似乎不是在平面结构中安装所有包,它正在模块目录中安装每个模块的依赖项.

I used npm install --dev to install the dependencies listed in a package.json file and it seems that rather than installing all the packages in a flat structure, it is installing the dependencies of each module inside the module's directory.

我不得不取消它,因为它花费了很多时间,因为许多依赖项应该已经得到满足,但它不得不将它们重新下载到不同的嵌套目录中(我希望没有循环,它最终会完成)...

I had to cancel it because it was taking a lot, because many dependencies should have been already satisfied but it had to re-download them in a different nested directory (and I hope that there are not loops and it would have eventually finished)...

使用 tree 命令,这是我得到的示例:

Using the tree command this is an example of what I am getting:

├── grunt-cli
│   └── node_modules
│       ├── findup-sync
│       │   └── node_modules
│       │       ├── glob
│       │       │   └── node_modules
│       │       │       ├── minimatch
│       │       │       │   └── node_modules
│       │       │       │       ├── lru-cache
│       │       │       │       │   └── node_modules
│       │       │       │       │       └── weak
│       │       │       │       │           └── node_modules
│       │       │       │       │               └── mocha
│       │       │       │       │                   └── node_modules
│       │       │       │       │                       ├── coffee-script
│       │       │       │       │                       │   └── node_modules
│       │       │       │       │                       │       └── jison
│       │       │       │       │                       │           └── node_modules
│       │       │       │       │                       │               └── browserify
│       │       │       │       │                       │                   └── node_modules
│       │       │       │       │                       │                       ├── browser-resolve
│       │       │       │       │                       │                       │   └── example

知道为什么会发生这种情况吗?

Any ideas why this might be happening?

推荐答案

别担心,这实际上是 Npm 的设计方式.您甚至可能会看到多次安装相同的模块(尽管通常具有不同的版本).

Don't worry, that's actually the way Npm was designed. You may even see the same module installed many times (though typically with different versions).

这个想法是,安装在 node_modules 下的每个模块都是该模块的某种独立安装,包括其依赖项和必要的版本——它不依赖于全局安装的模块.

The idea is that each module installed under node_modules is a somewhat self-contained installation of that module with its dependencies and the necessary versions -- it doesn't depend on modules installed globally.

如果您担心模块多次安装效率低下,实验性npm dedupe.

If you are worried about inefficiency of modules being installed multiple times, the experimental npm dedupe.

这篇关于npm 以一种奇怪的递归方式安装依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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