无法打开React Native应用:@stripe/stripe-react-native钩子文件缺失报错
解决React Native更换Stripe依赖后构建失败的问题
彻底清理依赖与缓存
删除旧依赖文件、锁文件,清空包管理器缓存后重新安装:rm -rf node_modules rm package-lock.json yarn.lock npm cache clean --force npm install(如果用yarn,把最后两句换成
yarn cache clean和yarn install)匹配Stripe包与React Native版本
不同版本的@stripe/stripe-react-native对React Native版本有要求,若你的RN版本较低,需安装适配的旧版本:npm install @stripe/stripe-react-native@^0.23.0具体适配版本可查看该包README里的版本兼容说明。
清理平台构建缓存
- iOS端:
cd ios pod deintegrate pod install rm -rf build - Android端:
cd android ./gradlew clean
- iOS端:
移除旧Stripe依赖的残留代码
全局搜索项目中所有tipsi-stripe相关的导入、调用代码,全部替换为@stripe/stripe-react-native的对应写法。比如旧的import { Stripe } from 'tipsi-stripe'要换成新包的import { useStripe } from '@stripe/stripe-react-native',残留的旧代码会导致构建时查找不存在的文件。重置Metro缓存并重启服务
关闭当前Metro服务器,执行以下命令重启:npx react-native start --reset-cache
内容的提问来源于stack exchange,提问作者Muhammad Saqib Noor
相关产品推荐
相关产品推荐

