15

I have a Dev dependency in my package.json file on protractor

"protractor": "~2.1",

However protractor uses an older version of

"selenium-webdriver": "2.45.1",

I need to update this to use 2.46.1. How can I override this in my package.json file? Currently to test it out I went to /node_modules/protractor/package.json and changed it there which made. I looked at npm-shrinkwrap but that seems to lock all the packages and I just want to override a single package

user3626708
  • 727
  • 2
  • 8
  • 24
  • 2
    Possible duplicate of [How do I override nested NPM dependency versions?](https://stackoverflow.com/questions/15806152/how-do-i-override-nested-npm-dependency-versions) – BBonifield Jun 18 '17 at 18:27

2 Answers2

8

NPM 8 introduced "overrides" which allows you to override specific transitive dependencies of your direct dependency. For your usecase, you would declare something like below.

{
  "overrides": {
    "protractor": {
      "selenium-webdriver": "2.46.1"
    }
  }
}

More details @ https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides

Sateesh
  • 735
  • 8
  • 10
  • 1
    FYI, it was specifically NPM 8.3.0 that introduced overrides. NPM <8.3 does not support overrides, despite the documentation making no distinction between 8.3 and earlier versions. – rob Mar 23 '22 at 15:55
4

For your problem you can user something called as npm shrinkwrap.

I think that is the way they explained it. Yes you are correct it locks down the dependency but, by doing so you also want same thing you want some specific dependency for your need.

Take a look at this question How do I override nested NPM dependency versions?

Community
  • 1
  • 1
Dnyanesh
  • 2,265
  • 3
  • 20
  • 17