为什么 npm install 执行后依赖包都跑到外面来了

2015-12-02 17:48:02 +08:00
 px1981
比如 npm install url
安装完成后, url 目录下没有 node_modules 子目录
原本应该出现在 node_modules 下的依赖模块跑到了 url 目录同一级目录里
4609 次点击
所在节点    Node.js
10 条回复
px1981
2015-12-02 17:49:33 +08:00
而且 url 的 package.json 也发生了变化
for8ever
2015-12-02 17:51:14 +08:00
我安装 url 没有出现你说的情况
px1981
2015-12-02 17:54:23 +08:00
@for8ever 你的 node 和 npm 是什么版本,我的是 5.1.0 和 3.3.12 ,找了三台机器都有这个问题
guchengf
2015-12-02 17:55:47 +08:00
npm 3 之后,所有 npm 模块改为平级
这样可以防止重复安装依赖包
px1981
2015-12-02 17:58:03 +08:00
@guchengf 可这样怎么依赖指定的版本呢
dofy
2015-12-02 18:05:12 +08:00
npm 3.0.0 修改了依赖包的安装位置。

参考: https://github.com/npm/npm/releases/tag/v3.0.0

搜 Flat
for8ever
2015-12-02 18:26:53 +08:00
原来如此。。。
guchengf
2015-12-02 19:15:03 +08:00
@px1981 根据实际情况来看,如果说某个模块的依赖与公共版本不一致,还是一样会在它的目录下建一个 node_modules 用来存放它的私有依赖版本
px1981
2015-12-02 23:08:44 +08:00
@guchengf 谢谢,在官方文档中也看到了“ You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies. ”
Wangxf
2015-12-02 23:31:04 +08:00
所以每次安装一个模块, node_modules 下面一大坨

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/240641

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX