React Native项目执行pod install遇Invalid Podfile错误求助
React Native执行
pod install报错"react-native-community/cli"的解决办法 问题详情
执行pod install安装iOS依赖时失败,报错信息:
Invalid Podfile file: "react-native-community/cli"
已尝试以下方案但均未解决:
- 先安装npm依赖再执行
pod install - 删除
node_modules后重新安装依赖再执行pod install
环境信息:
- Node版本:v16.16.0
- NPM版本:8.11.0
项目配置代码
package.json
{ "name": "shohan", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint ." }, "dependencies": { "@react-native-async-storage/async-storage": "^1.16.2", "@react-native-community/blur": "^3.6.0", "@react-native-community/cli-platform-ios": "^8.0.6", "@react-native-community/clipboard": "^1.5.1", "@react-native-community/datetimepicker": "^6.1.2", "@react-native-masked-view/masked-view": "^0.2.6", "@react-native-picker/picker": "^2.4.2", "@react-navigation/bottom-tabs": "^6.2.0", "@react-navigation/material-top-tabs": "^6.2.1", "@react-navigation/native": "^6.0.8", "@react-navigation/native-stack": "^6.5.0", "@rneui/base": "^0.0.0-edge.2", "@rneui/themed": "^0.0.0-edge.2", "@twotalltotems/react-native-otp-input": "^1.3.11", "axios": "^0.26.1", "moment": "^2.29.2", "radio-buttons-react-native": "^1.0.4", "react": "17.0.2", "react-hook-form": "^7.28.1", "react-native": "0.67.3", "react-native-animatable": "^1.3.3", "react-native-audio-record": "^0.2.2", "react-native-bar-chart": "^0.1.0", "react-native-countdown-component": "^2.7.1", "react-native-date-picker": "^4.2.0", "react-native-datepicker": "^1.7.2", "react-native-dropdown-picker": "^5.3.0", "react-native-elevation": "^1.0.0", "react-native-emoji-selector": "^0.2.0", "react-native-fs": "^2.20.0", "react-native-image-picker": "^4.8.4", "react-native-infinite-scrolling": "^2.0.0", "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-linear-gradient": "^2.5.6", "react-native-loading-spinner-overlay": "^3.0.0", "react-native-pager-view": "^5.4.15", "react-native-paper": "^4.12.1", "react-native-picker-select": "^8.0.4", "react-native-pure-chart": "^0.0.24", "react-native-render-html": "^6.3.4", "react-native-safe-area-context": "^4.1.2", "react-native-screens": "^3.13.1", "react-native-skeleton-placeholder": "^5.0.0", "react-native-snap-carousel": "^3.9.1", "react-native-sound": "^0.11.2", "react-native-step-indicator": "^1.0.3", "react-native-super-grid": "^4.4.0", "react-native-svg": "^12.4.0", "react-native-swiper-flatlist": "^3.0.16", "react-native-tab-view": "^3.1.1", "react-native-text-gradient": "^0.1.7", "react-native-vector-icons": "^9.1.0", "react-native-video": "^2.3.1", "react-native-video-player": "^0.12.0", "react-native-webview": "^11.18.1", "react-native-youtube-iframe": "^2.2.2", "socket.io-client": "^4.5.1" }, "devDependencies": { "@babel/core": "^7.17.5", "@babel/runtime": "^7.17.2", "@react-native-community/eslint-config": "^3.0.1", "babel-jest": "^27.5.1", "eslint": "^8.11.0", "jest": "^27.5.1", "metro-react-native-babel-preset": "^0.69.0", "react-test-renderer": "17.0.2" }, "jest": { "preset": "react-native" } }
Podfile
require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' platform :ios, '11.0' target 'shohan' do config = use_native_modules! use_react_native!( :path => config[:reactNativePath], # to enable hermes on iOS, change `false` to `true` and then install pods :hermes_enabled => false ) target 'shohanTests' do inherit! :complete # Pods for testing end # Enables Flipper. # # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable the next line. use_flipper!() post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer) end end
错误截图

问题原因
你的React Native版本是0.67.3,该版本对应的@react-native-community/cli-platform-ios兼容版本为6.x系列,但你安装的是8.0.6,版本过高导致Podfile中引用的native_modules脚本不兼容,出现模块路径错误。
解决步骤
- 卸载当前高版本的
@react-native-community/cli-platform-ios
npm uninstall @react-native-community/cli-platform-ios
- 安装与RN 0.67.3兼容的版本(推荐6.4.0)
npm install @react-native-community/cli-platform-ios@6.4.0 --save
- 清理依赖缓存并重新安装npm依赖
rm -rf node_modules package-lock.json npm install
- 进入iOS目录清理Pod缓存并重新安装
cd ios rm -rf Podfile.lock Pods pod install
内容的提问来源于stack exchange,提问作者Imdadul Haque
相关产品推荐
相关产品推荐

