patch-package
patch-package copied to clipboard
Patch-package does not consistently run in Google Cloud Functions
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.
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.
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:
- Change package.json description and version.
- 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 Did you find a solution?
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?
tested also with renewed package lock file. Could it be that script: postinstall is not working there?