Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patches not applied when using Heroku's Node buildpack #130

Closed
OliverJAsh opened this issue Mar 6, 2019 · 11 comments
Closed

Patches not applied when using Heroku's Node buildpack #130

OliverJAsh opened this issue Mar 6, 2019 · 11 comments

Comments

@OliverJAsh
Copy link
Contributor

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:

  1. install all dependencies (including devDependencies) with yarn --production="false"
  2. run build step
  3. prune dev dependencies with yarn --production="true"
  4. 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

@OliverJAsh
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@naiyt
Copy link

naiyt commented Nov 28, 2020

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"
  }

@neokim
Copy link

neokim commented May 12, 2021

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.

@esbanarango
Copy link

@neokim suggestion to use heroku-cleanup instead of heroku-postbuild worked for us. 🤝

@AlexanderPershin
Copy link

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?

@Previesam
Copy link

@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
Copy link

ChrisChiasson commented Sep 5, 2022

Warning: If you add heroku-postbuild, your build script will NOT execute: https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-process

@PaulBratslavsky
Copy link

Has anyone had this issue on digital ocean?

@IceBreaker8
Copy link

@Previesam @AlexanderPershin For strapi staging, I added:
"postinstall": "npx patch-package",
For prod, I also added:
"heroku-cleanup": "npx patch-package"

@benjie
Copy link

benjie commented Jan 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants