Locally I needed to fix a bug in an npm package, but when uploading the server to heroku, the npm gets reinstalled and my fix is of course gone. Is there a way to edit the file inside the node_modules folder inside heroku?
2 Answers 2
You should use patch-package package for that
https://www.npmjs.com/package/patch-package
Comments
I don't think patch-package by itself solves the problem you encountered. The problem is described in this issue logged in the patch-package project: https://github.com/ds300/patch-package/issues/130
It says:
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-scriptsflag when callingyarn(since v119). This means [your post-install script] 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 (!).
As per the 'Skip Pruning' section of this Heroku doc, you can set environment variables to skip pruning. Alternatively, you might be able to (re-)apply your patch in the "heroku-postbuild" step.