question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Patches not applied when using Heroku's Node buildpack

See original GitHub issue

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: https://github.com/heroku/heroku-buildpack-nodejs/issues/634

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
naiytcommented, 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"
  }
6reactions
neokimcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting Node.js Deploys - Heroku Dev Center
Your Node.js deploy failed - now what? Start with these simple steps to troubleshoot a build issue. Check the buildpack.
Read more >
Heroku Node.js Support
Reference documentation describing the the support for Node.js on Heroku's Cedar stack.
Read more >
Why does my app "fail to detect" a buildpack? - Heroku Help
This error message means that Heroku was unable to automatically detect the type of app you're trying to deploy: Ruby, Node, Python, PHP,...
Read more >
heroku-buildpack-nodejs
You can set it using the heroku-cli . heroku buildpacks:set heroku/nodejs. Your builds will always used the latest published release of the buildpack....
Read more >
Node.js buildpack improved support for Yarn 2.x & 3.x ...
For Node applications using the heroku/nodejs buildpack and Yarn 2.x ... it is used to control dependency pruning with Yarn 1.x but is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found