px1981
V2EX  ›  Node.js

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

  •  
  •   px1981 · Dec 2, 2015 · 5528 views
    This topic created in 3821 days ago, the information mentioned may be changed or developed.
    比如 npm install url
    安装完成后, url 目录下没有 node_modules 子目录
    原本应该出现在 node_modules 下的依赖模块跑到了 url 目录同一级目录里
    10 replies    2015-12-02 23:31:04 +08:00
    px1981
        1
    px1981  
    OP
       Dec 2, 2015
    而且 url 的 package.json 也发生了变化
    for8ever
        2
    for8ever  
       Dec 2, 2015
    我安装 url 没有出现你说的情况
    px1981
        3
    px1981  
    OP
       Dec 2, 2015
    @for8ever 你的 node 和 npm 是什么版本,我的是 5.1.0 和 3.3.12 ,找了三台机器都有这个问题
    guchengf
        4
    guchengf  
       Dec 2, 2015
    npm 3 之后,所有 npm 模块改为平级
    这样可以防止重复安装依赖包
    px1981
        5
    px1981  
    OP
       Dec 2, 2015
    @guchengf 可这样怎么依赖指定的版本呢
    dofy
        6
    dofy  
       Dec 2, 2015
    npm 3.0.0 修改了依赖包的安装位置。

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

    搜 Flat
    for8ever
        7
    for8ever  
       Dec 2, 2015
    原来如此。。。
    guchengf
        8
    guchengf  
       Dec 2, 2015
    @px1981 根据实际情况来看,如果说某个模块的依赖与公共版本不一致,还是一样会在它的目录下建一个 node_modules 用来存放它的私有依赖版本
    px1981
        9
    px1981  
    OP
       Dec 2, 2015
    @guchengf 谢谢,在官方文档中也看到了“ You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies. ”
    Wangxf
        10
    Wangxf  
       Dec 2, 2015
    所以每次安装一个模块, node_modules 下面一大坨
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2649 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 15:36 · PVG 23:36 · LAX 08:36 · JFK 11:36
    ♥ Do have faith in what you're doing.