How do I override nested NPM dependency versions?

前端 未结 6 1198
[愿得一人]
[愿得一人] 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
    2020-11-22 14:23

    The only solution that worked for me (node 12.x, npm 6.x) was using npm-force-resolutions developed by @Rogerio Chaves.

    First, install it by:

    npm install npm-force-resolutions --save-dev
    

    You can add --ignore-scripts if some broken transitive dependency scripts are blocking you from installing anything.

    Then in package.json define what dependency should be overridden (you must set exact version number):

    "resolutions": {
      "your-dependency-name": "1.23.4"
    }
    

    and in "scripts" section add new preinstall entry:

    "preinstall": "npx npm-force-resolutions",
    

    Now, npm install will apply changes and force your-dependency-name to be at version 1.23.4 for all dependencies.

提交回复
热议问题