You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Patches not applied when using Heroku's Node buildpack #130
This isn't an issue with patch-package specifically, but I wanted to share it here nonetheless to help anyone else who might run into this.
When using Heroku's Node buildpack, by default the following will happen during the build and startup process:
install all dependencies (including devDependencies) with yarn --production="false"
run build step
prune dev dependencies with yarn --production="true"
run the app
However, at step 3 when the dev dependencies are pruned, the buildpack also specifies the --ignore-scripts flag when calling yarn (since v119). This means patch-package will not run, because the postinstall/prepare scripts will not be ran. In turn, this means when the app runs, Node modules will not be patched (!).
I can semi-understand why the buildpack would want to avoid invoking scripts, since the scripts were already run after step 1. In any case I've raised an issue with the buildpack to investigate what changes we can make there: heroku/heroku-buildpack-nodejs#634
Reacted by gunar, Hugh Berryman, modermo, Nigel Lima, Abdullah Mzaien, Jordan Phillips and Alexander
Immediately closing this as it's not a bug with patch-package, but hopefully this will be helpful to others. @ds300 If you have ideas for alternative workarounds or fixes, I'd love to hear them!
I just ran into this again when setting up patch-package on a fresh Heroku application. Perhaps we should add a note to the docs for Heroku users: #209
Looks like with the latest version of the Heroku nodejs build script, you can accomplish this by using the heroku-postbuild step. That allows patch-package to work without losing the dev dependency pruning 🎉 .
Here's what my package.json scripts look like now:
Reacted by Jordan Phillips, chr4ss1, Saffet Emin Reisoğlu, J03L R0J0, Justin Brush, Esteban, Eliaz Bobadilla, 0101DigitAll, Gabriel Okamoto, Alexander and 1 more
Reacted by Jeremy W. Sherman, Esteban and Eliaz Bobadilla
heroku-postbuild didn't work for me. Looks like during pruning dev dependencies which runs after heroku-postbuild, yarn restores the original version of packages. So I had to use heroku-cleanup instead which runs after pruning.
Actually, Heroku document says it runs after dependency caching, but it works for me anyway.
Reacted by Rohan Deshpande, Esteban, Viktor Futo, Gabriel Okamoto, Alexander and Rihards Fridrihsons
So i added "postinstall": "npx patch-package", "heroku-postbuild": "npx patch-package", "heroku-cleanup": "npx patch-package" but looking at the logs only heroku cleanup should do the trick.
@Previesam@AlexanderPershin For strapi staging, I added:
"postinstall": "npx patch-package",
For prod, I also added:
"heroku-cleanup": "npx patch-package"
The solution is to add the heroku-cleanup (different from heroku-postbuild) script to your "scripts" in package.json; the reason being that the Heroku cleanup clears out the devDependencies, which triggers another call to your package manager, ignoring scripts, and thus patch-package is not called again. This causes issues for yarn at least.
Activity
OliverJAsh commentedon Mar 6, 2019
Immediately closing this as it's not a bug with
patch-package, but hopefully this will be helpful to others. @ds300 If you have ideas for alternative workarounds or fixes, I'd love to hear them!OliverJAsh commentedon Feb 20, 2020
I just ran into this again when setting up
patch-packageon a fresh Heroku application. Perhaps we should add a note to the docs for Heroku users: #209naiyt commentedon Nov 28, 2020
Looks like with the latest version of the Heroku nodejs build script, you can accomplish this by using the
heroku-postbuildstep. That allowspatch-packageto work without losing the dev dependency pruning 🎉 .Here's what my
package.jsonscripts look like now:neokim commentedon May 12, 2021
heroku-postbuilddidn't work for me. Looks like during pruning dev dependencies which runs afterheroku-postbuild,yarnrestores the original version of packages. So I had to useheroku-cleanupinstead which runs after pruning.Actually, Heroku document says it runs after dependency caching, but it works for me anyway.
esbanarango commentedon Dec 15, 2021
@neokim suggestion to use
heroku-cleanupinstead ofheroku-postbuildworked for us. 🤝AlexanderPershin commentedon Jun 17, 2022
I added
"heroku-cleanup": "npx patch-package"to my package.json for Strapi appand output shows
But no changes applyed. What am I doing wrong?
Previesam commentedon Aug 2, 2022
@AlexanderPershin It worked for me I am also using strapi.
So i added
"postinstall": "npx patch-package","heroku-postbuild": "npx patch-package","heroku-cleanup": "npx patch-package"but looking at the logs only heroku cleanup should do the trick.ChrisChiasson commentedon Sep 5, 2022
Warning: If you add
heroku-postbuild, yourbuildscript will NOT execute: https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-processPaulBratslavsky commentedon Oct 23, 2022
Has anyone had this issue on digital ocean?
IceBreaker8 commentedon Dec 30, 2022
@Previesam @AlexanderPershin For strapi staging, I added:
"postinstall": "npx patch-package",
For prod, I also added:
"heroku-cleanup": "npx patch-package"
benjie commentedon Jan 23, 2023
The solution is to add the
heroku-cleanup(different fromheroku-postbuild) script to your "scripts" inpackage.json; the reason being that the Heroku cleanup clears out the devDependencies, which triggers another call to your package manager, ignoring scripts, and thuspatch-packageis not called again. This causes issues foryarnat least.Thanks to @IceBreaker8 above for the solve.