Patches not applied when using Heroku's Node buildpack
See original GitHub issueThis 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: https://github.com/heroku/heroku-buildpack-nodejs/issues/634
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:9 (2 by maintainers)
Top GitHub Comments
Looks like with the latest version of the Heroku nodejs build script, you can accomplish this by using the
heroku-postbuild
step. That allowspatch-package
to work without losing the dev dependency pruning 🎉 .Here’s what my
package.json
scripts look like now:heroku-postbuild
didn’t work for me. Looks like during pruning dev dependencies which runs afterheroku-postbuild
,yarn
restores the original version of packages. So I had to useheroku-cleanup
instead which runs after pruning.Actually, Heroku document says it runs after dependency caching, but it works for me anyway.