patch-package icon indicating copy to clipboard operation
patch-package copied to clipboard

Patch-package does not consistently run in Google Cloud Functions

Open ccw-morris opened this issue 5 years ago β€’ 5 comments

This is an advisory note, to assist others with the same issue, rather than a request to change anything.

Google Cloud Functions is capable of running patch-package as a postinstall script as part of deployment of the function. But, it doesn't do it every time.

It appears that Cloud Functions cache the node_modules directory against a hash of the package.json file. So, if the patches are updated without changing package.json then the new patches will not be applied. Similarly, if the package.json is reverted to an earlier version that coexisted with a different set of patches then the function will use those earlier patches rather than the patches that currently exist in the cloud function bundle.

The solution is to always make a change to package.json whenever the patches directory is changed. To test this in my project, I changed one of the author tags and the current patches were applied correctly.

The observation about a cache is a guess based on generating different functions and observing the effects. Unfortunately, Google does not expose the deployment logs or code to enable verification.

ccw-morris avatar Jul 26 '19 10:07 ccw-morris

This kind of thing has come up before and I'd be open to the idea of having patch-package update a hash value in the package.json whenever the contents of the patches dir changes.

ds300 avatar Sep 06 '19 11:09 ds300

I had the same issue, thanks for letting us know. However, it seems like my functions are still working didn't apply the patches.

The steps I did:

  1. Change package.json description and version.
  2. Deploy to Firebase.

UPDATE: Also tried:

  • Install a new package (randomly) -> Deploy
  • Uninstall a package -> Deploy
  • Delete all functions -> Deploy

Neither worked.. On my local environment, β€œnpm install” works just fine with the library.

What am I missing?

romshiri avatar Oct 19 '19 20:10 romshiri

@romshiri Did you find a solution?

manwithsteelnerves avatar Mar 03 '21 11:03 manwithsteelnerves

it could be only the yarn/npm lock file that is used as a cache key? Maybe try adding a comment in there with a hash of the patches dir before deploying?

ds300 avatar Mar 04 '21 08:03 ds300

tested also with renewed package lock file. Could it be that script: postinstall is not working there?

CrackerakiUA avatar Sep 06 '22 10:09 CrackerakiUA