`patch-package` fails to apply changes when switching between branches
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 325
- PR merge metrics
- No merged PRs in 30d
Description
# 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
1. Checkout a branch in your repo e.g. `patch-package-1`.
2. Patch any library and commit the changes.
3. Checkout a new branch based on this one e.g. `patch-package-2`.
4. Patch the library again with new code and commit the changes.
5. 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
1. Checkout a branch in your repo e.g. `patch-package-1`.
2. Patch any library and commit the changes.
3. Checkout a new branch based on this one e.g. `patch-package-2`.
4. Patch the library again with new code using `--append` and commit the changes.
5. Switch from `patch-package-2` to `patch-package-1` and try to install dependencies, you will always get an error and the patch won’t be applied, unless you delete `node_modules` (same error as Case 1).
6. ⚠️ Switching from `patch-package-1` to `patch-package-2` won't cause this error.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.