patch-package
patch-package copied to clipboard
`patch-package` fails to apply changes when switching between branches
Case 1
Details
When switching between two branches that modifies a patch file, it will cause patch-package to always fail to apply the changes unless you delete node_modules.
Steps to reproduce
- Checkout a branch in your repo e.g.
patch-package-1. - Patch any library and commit the changes.
- Checkout a new branch based on this one e.g.
patch-package-2. - Patch the library again with new code and commit the changes.
- Switch between the branches and try to install dependencies, you will always get an error and the patch wonβt be applied, unless you delete
node_modules.
**ERROR** Failed to apply patch for package expensify-common at path
node_modules/expensify-common
This error was caused because patch-package cannot apply the following patch file:
patches/expensify-common+1.0.0.patch
Try removing node_modules and trying again. If that doesn't work, maybe there was
an accidental change made to the patch file? Try recreating it by manually
editing the appropriate files and running:
patch-package expensify-common
If that doesn't work, then it's a bug in patch-package, so please submit a bug
report. Thanks!
https://github.com/ds300/patch-package/issues
---
patch-package finished with 1 error(s).
Case 2
Details
When switching from a branch that uses multi-patches feature in a library to a branch that does not in the same library, it will cause patch-package to always fail to apply the changes unless you delete node_modules.
Steps to reproduce
- Checkout a branch in your repo e.g.
patch-package-1. - Patch any library and commit the changes.
- Checkout a new branch based on this one e.g.
patch-package-2. - Patch the library again with new code using
--appendand commit the changes. - Switch from
patch-package-2topatch-package-1and try to install dependencies, you will always get an error and the patch wonβt be applied, unless you deletenode_modules(same error as Case 1). - β οΈ Switching from
patch-package-1topatch-package-2won't cause this error.
The issue is not patch package. It is your node_modules being modified. When you switch branches, git switching you between your own code versions and ignoring changes in node_modules. You need to do a clean install for your app dependencies. Add a npm script like https://github.com/sahat/hackathon-starter/blob/1d136821bb80d251688e80ebce8407700fe1d242/package.json#L15 and run it whenever you switch branches.