How do modifications in node-modules package code??

Are you in a situation where you have to change code in node-module package? Sometimes you have some code snippet you want to change in node module package code but its not advisable to do that because when you install any other package the changes done in package will revert back t original. And in some situations node-modules work after making build of that package so in any case its not correct to change anything in node-modules package.

So how to change code in node-module package ?? Can we do it??

Yes, we can do it. By following below steps:

  1. Fork the package from GitHub or clone the required package my-package from GitHub.
  2. When it get cloned in your local system run command to install the required dependencies yarn install.(using yarn for package installation)
  3. Then run command yarn build. This will make build which can created after making required changes in the dependencies.
  4. Now we have to link our project with this dependency. So now how to link our project with our dependency my-package?

For this we have to install yalc package globally into our system using the command yarn global add yalc. Why we are using this package, as linking functionality is available in both npm and yarn . Because if these are used, it throws Invalid Hook Warning. That’s why yalc package is required. Commands and setup for yalc are below:

  1. Run yalc publish in your dependency package my-package. This will create build and make my-package available for linking. It will copy all the files that should be published in remote NPM.
  2. Run yalc add my-package in your dependent project, which will copy the current version from the store to your project’s .yalc  folder and inject a file: .yalc/my-package dependency into package.json.
  3. With yarn start application can be started.

Now every time if some changes are done in my-package then we have to run yalc publish in dependency and to get the latest code lined to our project , we have to run yalc add my-package.

A After that my-package can be pushed to GitHub and can be included in the package.json file. Or directly make the build by yarn run build and then you can host the application even without pushing my-package to GitHub.

2 thoughts on “How do modifications in node-modules package code??

Add yours

Leave a comment

Website Powered by WordPress.com.

Up ↑