How do I override nested NPM dependency versions?

前端 未结 6 1196
[愿得一人]
[愿得一人] 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 14:32

    NPM shrinkwrap offers a nice solution to this problem. It allows us to override that version of a particular dependency of a particular sub-module.

    Essentially, when you run npm install, npm will first look in your root directory to see whether a npm-shrinkwrap.json file exists. If it does, it will use this first to determine package dependencies, and then falling back to the normal process of working through the package.json files.

    To create an npm-shrinkwrap.json, all you need to do is

     npm shrinkwrap --dev
    

    code:

    {
      "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"
            }
          }
        }
      }
    }
    

提交回复
热议问题