georgebrock georgebrock - 8 months ago 627
Node.js Question

How do I override nested NPM dependency versions?

I would like to use the

NPM package. It has various dependencies. Part of the dependency graph looks like this:

─┬ grunt-contrib-jasmine@0.4.1
│ ├─┬ grunt-lib-phantomjs@0.2.0
│ │ ├─┬ phantomjs@1.8.2-2

Unfortunately, there's a bug in this version
which prevents it from installing correctly on Mac OS X. This is fixed in the latest version.

How can I get
to use a newer version of

Some additional context:


You've probably found a workaround for this already.

Anyway, 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.