Skip to content

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

Closed

Description

@OliverJAsh

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

Activity

  1. OliverJAsh commented on Mar 6, 2019

    @OliverJAsh
    ContributorAuthor

    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!

  2. OliverJAsh commented on Feb 20, 2020

    @OliverJAsh
    ContributorAuthor

    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

  3. naiyt commented on Nov 28, 2020

    @naiyt

    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"
      }
    
  4. neokim commented on May 12, 2021

    @neokim

    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.

  5. esbanarango commented on Dec 15, 2021

    @esbanarango

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

  6. AlexanderPershin commented on Jun 17, 2022

    @AlexanderPershin

    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?

  7. Previesam commented on Aug 2, 2022

    @Previesam

    @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.

  8. ChrisChiasson commented on Sep 5, 2022

    @ChrisChiasson

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

  9. PaulBratslavsky commented on Oct 23, 2022

    @PaulBratslavsky

    Has anyone had this issue on digital ocean?

  10. IceBreaker8 commented on Dec 30, 2022

    @IceBreaker8

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

  11. benjie commented on Jan 23, 2023

    @benjie

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions