DEV Community

Cover image for The easiest way to patch your npm package when there is a 🐛

The easiest way to patch your npm package when there is a 🐛

Zhitomir Oreshenski on December 05, 2020

What do you do when you are working on npm-based project and encounter an issue with one of your dependecies? The easiest way and actually most d...
Collapse
 
jdnichollsc profile image
J.D Nicholls

This article is so helpful, thanks for sharing! <3

Collapse
 
vishal38isharani profile image
Vishal isharani

Very good solution, thanks a bunch @zhnedyalkow

Collapse
 
jcubic profile image
Jakub T. Jankiewicz

Very useful. Thanks for sharing.

Collapse
 
zhnedyalkow profile image
Zhitomir Oreshenski

Nice to hear that!

Collapse
 
jcubic profile image
Jakub T. Jankiewicz • Edited

One note you can try to color the snippets with Github like code blocks. (triple backticks and name of the language).

Thread Thread
 
zhnedyalkow profile image
Zhitomir Oreshenski

Great, I did not know that. Thank you, I will update the post tomorrow

Collapse
 
xpalacincreditoh profile image
Xavier Palacín Ayuso

How do you patch a package with @ in the name eg @namespace/package?

Collapse
 
smetankajakub profile image
Jakub Smetanka • Edited

Probably its not relevant for you anymore, but can help to others :)
Image description from official doc.

Collapse
 
obayit profile image
Obay Abdelgadir

Thanks, this helped me.

Collapse
 
mohsen0 profile image
Mohsen

so there is no way to run a patch when we run npm install --production, because running npm install will ship the dev deps with the application. any suggestions?

Collapse
 
thidasapankaja profile image
Thidasa Pankaja Paranavitharana

But is this safe for production apps ? Like medium scaled ones with number of users ?

Collapse
 
zhnedyalkow profile image
Zhitomir Oreshenski

Yes, it is safe

Collapse
 
gauravksoni profile image
Gaurav Kant Soni • Edited

While running yarn patch-package packageName it gives the following error

Request failed \"401 Unauthorized\
I have deleted the registry and npmrc still no luck

Collapse
 
reinholdmain profile image
Daniel Main

What if I need to change something in package.json ? due this is being executed in postinstall any patch-changes in package.json are useless :(