Patches not applied when using Heroku's Node buildpack
OliverJAsh opened this issue ยท 11 comments
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
) withyarn --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 (!).
The only workaround I'm aware of at the moment is to disable pruning of dev dependencies with YARN_PRODUCTION=false
.
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
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:
"scripts": {
"postinstall": "patch-package",
"heroku-postbuild": "patch-package"
}
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.
@neokim suggestion to use heroku-cleanup
instead of heroku-postbuild
worked for us. ๐ค
I added "heroku-cleanup": "npx patch-package"
to my package.json for Strapi app
and output shows
remote: -----> Cleanup
remote: Running heroku-cleanup
remote:
remote: > my-project@0.1.0 heroku-cleanup
remote: > npx patch-package
remote:
remote: patch-package 6.4.7
remote: Applying patches...
remote: @strapi/admin@4.1.12 โ
But no changes applyed. What am I doing wrong?
@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.
Warning: If you add heroku-postbuild
, your build
script will NOT execute: https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-process
Has anyone had this issue on digital ocean?
@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.
{
// ...
"scripts": {
"heroku-cleanup": "npx patch-package",
// ...
Thanks to @IceBreaker8 above for the solve.