Error :
**ERROR** Failed to apply patch for package react-native at path
node_modules/react-native
This error was caused because patch-package cannot apply the following patch file:
patches/react-native+0.64.2.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 react-native
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
Understanding the error:
This error occurs when patch-package fails to apply a patch file to one of your dependencies — in this case, React Native.
The patch file (patches/react-native+0.64.2.patch) may no longer match the current version of React Native in your project.
Common causes include:
- A version mismatch between package.json and yarn.lock.
- The patch file is outdated due to upgrading React Native.
- The patch file was accidentally modified or corrupted.
- You reinstalled dependencies and the patch no longer aligns with the current node_modules structure.
Quick Solution
The solution is mostly in the error itself you will have to run :
npx patch-package react-native
This is incase no patch needs to be applied anymore.
Alternative Solutions
- Reinstall dependencies and rebuild lock file
Sometimes the version mismatch is between package.json and yarn.lock.
Remove both and reinstall dependencies to ensure consistency:
rm -rf node_modules yarn.lock
yarn install
- Downgrade patch-package
If you’re on a newer version of patch-package that causes compatibility issues, downgrade to version 5.0.0, which is known to be stable.
In your package.json:
"patch-package": "^5.0.0",
Then reinstall dependencies:
yarn install