3

Is it possible to force an external npm dependency to use a different node.js package that offers the same API but a different implementation?

2
  • Did you have a specific use case? The answer could vary Commented Feb 11, 2016 at 20:24
  • Here is my use case. I've found a bug in the following module: /node_modules/react-router/node_modules/history/node_modules/query-string/index.js How can I substitute that module (query-string) with a fixed one (there is a fork that contains the fix) Commented May 23, 2016 at 23:31

3 Answers 3

1

If you're willing to do that and that module is open source you could fork that on github, change their package.json to include the module you want and use github url for your own package.json like this:

"modulename": "git+https://[email protected]/user/repo.git"
0

You should be able to download the source of whatever module you would prefer and put that folder within your node_modules folder. From that point you simply require it within your Node.js app like any other NPM module.

0

I recommend downloading the code for the API you want, creating an src/assets folder, placing it in there, changing the package name in package.json to something not used in npm, then using 'require('newPackageName')' within your code.

If you decide to use some of package.json's capabilities to point towards a specific version (like using "1.4.7" as opposed to "^1.4.7") or if you point to a github address, be careful when you run npm update. It will replace your URL with the latest version in npmjs.org with that specific name. I don't know if it still does this in newer versions of npm, but in the version that works with Node.js 0.12, this is the default behavior.

I can tell you that node shrinkwrap will work, but it will prevent any other packages from being updated as well. No, you cannot just have one shrinkwrapped dependency, it has to be all of them, or npm update won't work.

Not the answer you're looking for? Browse other questions tagged or ask your own question.