How do I override nested NPM dependency versions?

前端 未结 6 1197
[愿得一人]
[愿得一人] 2020-11-22 13:51

I would like to use the grunt-contrib-jasmine NPM package. It has various dependencies. Part of the dependency graph looks like this:

─┬ grunt-c         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 14:24

    You can use npm shrinkwrap functionality, in order to override any dependency or sub-dependency.

    I've just done this in a grunt project of ours. We needed a newer version of connect, since 2.7.3. was causing trouble for us. So I created a file named npm-shrinkwrap.json:

    {
      "dependencies": {
        "grunt-contrib-connect": {
          "version": "0.3.0",
          "from": "grunt-contrib-connect@0.3.0",
          "dependencies": {
            "connect": {
              "version": "2.8.1",
              "from": "connect@~2.7.3"
            }
          }
        }
      }
    }
    

    npm should automatically pick it up while doing the install for the project.

    (See: https://nodejs.org/en/blog/npm/managing-node-js-dependencies-with-shrinkwrap/)

提交回复
热议问题