Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use fork version of npm package in a project

Tags:

node.js

npm

Let's say there is an npm package called abcd. Normally in package.json, we specified the dependencies as "abcd": "^1.0.0",

But this abcd does not work as expected, so I forked (and modified) it inside https://github.com/mygithubid/abcd

Then I run npm install git+https://[email protected]/mygithubid/abcd.git and in package.json, the definition is changed to "abcd": "git+https://github.com/mygithubid/abcd.git",

After restarting the project that using this abcd, now it throws error Module not found: Can't resolve 'abcd' ... even though I saw the abcd folder is added inside node_modules

Could you advise the mistake I made in above? Thanks!

like image 958
iwan Avatar asked Nov 05 '17 13:11

iwan


People also ask

How do I install a specific version of an npm module?

Use npm list [package-name] to know the specific latest version of an installed package. Use npm install [package-name]@[version-number] to install an older version of a package. Prefix a version number with a caret (^) or a tilde (~) to specify to install the latest minor or patch version, respectively.


2 Answers

One fairly clean option is to use patch-package: https://www.npmjs.com/package/patch-package

If the people using your project might use either npm or yarn, then remeber to make the patch available for both. More info under patch-package --use-yarn.

Patch or fork? See https://www.npmjs.com/package/patch-package#benefits-of-patching-over-forking

like image 78
Simon B. Avatar answered Sep 22 '22 07:09

Simon B.


Be sure that the github repository contains compiled files, at most cases you need build the package for npm first, the compiled files push only to NPM. To find out how to build the package check the package.json file

like image 32
Mohammad Reza Zarei Avatar answered Sep 19 '22 07:09

Mohammad Reza Zarei