节点程序包管理器(NPM)似乎产生重复的程序包 [英] The Node Package Manager (NPM) seems to yield duplicated packages

查看:79
本文介绍了节点程序包管理器(NPM)似乎产生重复的程序包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在安装一些节点程序包,我注意到NPM创建了一堆重复项.

I've been installing a few node packages and what I noticed is that NPM creates a bunch of duplicates.

例如,我首先安装了mongoose,它自然地安装了一堆依赖项.然后,我安装了mongodb软件包,该软件包也随bson一起提供了依赖项.由于重叠的依赖关系,我有以下异常情况:

For example, I first installed mongoose, which installed a bunch of dependencies, naturally. Then I installed the mongodb package, which also came with bson as a dependency. Due to overlapping dependencies, I have the following anomaly:

Mongodb位于以下目录中:

Mongodb is present in the following directories:

/usr/local/lib/node_modules/mongodb/
/usr/local/lib/node_modules/mongoose/node_modules/mongodb/

另外,bson,这两种情况中都存在mongodb的依赖项:

Also, bson, a dependency of mongodb is present in both of these:

/usr/local/lib/node_modules/mongodb/
/usr/local/lib/node_modules/mongoose/node_modules/mongodb/

我意识到这些只是千字节的文件,但是我觉得这可能会创建很多冗余端,最终可能会得到一个非常复杂的树,类似于以下内容:

I realize these are only files of kilobytes, but I feel like this might create a lot of redundancy end I might end up with a very complex tree similar to the following:

/usr/local/lib/node_modules/[something1]/node_modules/[something2]/node_modules/[something3/.../.../node_modules/[somethingX]/

在这种情况下,给定的[依赖性]可能存在于/usr/local/lib/node_modules下的X级别.

In this scenario a given [dependency] might be present on X levels under /usr/local/lib/node_modules.

我最关心的是与更新这些模块有关.我不难想象会同时安装不同版本的并发模块.

My major concern is related to updating these modules. I do not find it hard to imagine to have concurrent modules of different versions installed at the same time.

直接将所有内容直接放在/usr/local/lib/node_modules/中,然后交叉引用依赖关系会更容易吗?

Wouldn't it be easier to just put everything directly in /usr/local/lib/node_modules/ and then cross-reference dependencies?

推荐答案

问题是当mongoose仅被编码为可与mongodb的v1一起使用时,而您已将应用程序编码为可与mongodb的v2一起使用-如此,它会安装并加载两个版本,因此一切正常.我们可以轻松地在节点上完成此操作,因为require模块不会污染全局名称空间,这与浏览器不同-浏览器使管理和包括正确的依赖项成为全球命名空间污染的痛苦.

The problem is when mongoose is only coded to work with say v1 of mongodb, and you've coded your app to work with v2 of mongodb - as such, it installs and loads up both versions so it all works. We can do this easily in node, as the require module way doesn't pollute the global namespace, unlike the browser - which makes managing and including the right dependencies a royal pain due the global namespace pollution.

现在,如果您的package.json和mongoose的package.json允许相同的mongodb版本(您可以指定特定版本或范围),那么执行rm -Rf node_modules; npm install将仅安装mongodb的一个副本,而不是两个副本.但是,如前所述,如果指定了多个版本,则会安装和加载多个版本.

Now if your package.json and mongoose's package.json allow the same mongodb version (your can specify a specific version or ranges), then doing a rm -Rf node_modules; npm install will only install one copy of mongodb, rather than two. However as said before, if multiple versions are specified, multiple versions will be installed and loaded.

这篇关于节点程序包管理器(NPM)似乎产生重复的程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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