问题
根据patch-package文档创建补丁步骤
- 修改node_modules中的第三方库需要修改的源码
- 调用命令创建[假设我们修改了react-native的源码]
npx patch-package react-native
- 我们会得到react-native+0.59.10.patch文件
- package.json文件
"scripts": {
"postinstall": "patch-package",
},
- npm install结束后会安装该patch文件
注意:如果使用yarn install 就会在安装patch文件时会出现报错。
解决方案
方案1
创建补丁时使用
npx patch-package react-native --use-yarn
方案2
删除根目录中的package-lock.json文件保留yarn.lock
参考文档
--use-yarn
By default, patch-package checks whether you use npm or yarn based on which lockfile you have. If you have both, it uses npm by default. Set this option to override that default and always use yarn.
补丁对比
npm版本 <------------------------------------------>yarn版本