V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
0pens0urce
V2EX  ›  问与答

同一个项目内包含多个版本的 node_modules 是否可行?

  •  
  •   0pens0urce · Aug 24, 2018 · 2250 views
    This topic created in 2815 days ago, the information mentioned may be changed or developed.
    在同一个项目里设置多个版本的 node_modules,运行时通过指定参数选取不同的 node_modules 运行,这种做法是否可行?
    5 replies    2018-08-27 22:52:35 +08:00
    lrz0lrz
        1
    lrz0lrz  
       Aug 24, 2018
    使用 NODE_PATH 或者 NODE_PRESERVE_SYMLINKS 应该都可以解决这个问题。
    weixiangzhe
        2
    weixiangzhe  
       Aug 24, 2018
    webpack 的话可以设置 resolve

    ```js
    ....
    resolve: {
    modules: [
    path.resolve(__dirname, 'other_modules/node_modules'),
    'node_modules',
    ],
    },
    ...

    ```
    0pens0urce
        3
    0pens0urce  
    OP
       Aug 27, 2018
    @lrz0lrz 请问 NODE_PATH 是指系统变量吧?设置了没有效果
    lrz0lrz
        4
    lrz0lrz  
       Aug 27, 2018
    @0pens0urce #3 https://github.com/run-ze/NODE_PATH-demo
    你设置的方式不对吧?
    参照我这个 package.json
    0pens0urce
        5
    0pens0urce  
    OP
       Aug 27, 2018
    NODE_PATH=$(pwd)/another-package/node_modules node app 在 windows 环境下不能运行
    改成 set NODE_PATH=./another-package/node_modules&&node app 可以了
    @lrz0lrz 非常感谢你的帮助
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2759 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 15:35 · PVG 23:35 · LAX 08:35 · JFK 11:35
    ♥ Do have faith in what you're doing.