ds300 / patch-package

Fix broken node modules instantly 🏃🏽‍♀️💨
MIT License
10.31k stars 288 forks source link

Patch-package does not consistently run in Google Cloud Functions #160

Open ccw-morris opened 5 years ago

ccw-morris commented 5 years ago

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.

ds300 commented 5 years ago

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.

romshiri commented 4 years ago

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:

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

What am I missing?

manwithsteelnerves commented 3 years ago

@romshiri Did you find a solution?

ds300 commented 3 years ago

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?

CrackerakiUA commented 2 years ago

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