包子!
包子!
发布于 2023-11-27 / 119 阅读 / 1 评论 / 0 点赞

使用Taro的React Native端遇到的Invalid `Podfile` file问题

Invalid `Podfile` file报错

React Native 端开发流程使用分离模式时,执行yarn upgradePeerdeps

遇到如下报错:

yarn run v1.22.19
$ install-peerdeps @tarojs/taro-rn@3.5.7-alpha.8 -o -Y && install-peerdeps @tarojs/components-rn@3.5.7-alpha.8 -o -Y && install-peerdeps @tarojs/router-rn@3.5.7-alpha.8 -o -Y && pod-install
install-peerdeps v3.0.3
Installing peerdeps for @tarojs/taro-rn@3.5.7-alpha.8.
yarn add @react-native-async-storage/async-storage@~1.17.7 @react-native-camera-roll/camera-roll@~5.0.4 @react-native-clipboard/clipboard@~1.11.1 @react-native-community/geolocation@~3.0.2 @react-native-community/netinfo@~9.3.0 expo-av@~13.0.0 expo-barcode-scanner@~12.0.0 expo-brightness@~11.0.0 expo-camera@~13.0.0 expo-file-system@~15.1.1 expo-image-picker@~14.0.0 expo-keep-awake@~11.0.1 expo-location@~15.0.1 expo-modules-core@~1.0.2 expo-sensors@~12.0.1 react-native-device-info@~10.3.0 react-native-image-resizer@~1.4.5 react-native-safe-area-context@~4.4.1 react-native-syan-image-picker@0.5.3

SUCCESS The peerDeps of @tarojs/taro-rn were installed successfully.
install-peerdeps v3.0.3
Installing peerdeps for @tarojs/components-rn@3.5.7-alpha.8.
yarn add @react-native-community/slider@~4.3.2 @react-native-picker/picker@~2.4.2 expo@~47.0.3 expo-av@~13.0.0 expo-barcode-scanner@~12.0.0 expo-camera@~13.0.0 react-native-pager-view@~6.0.1 react-native-svg@~13.4.0 react-native-webview@~11.23.0

SUCCESS The peerDeps of @tarojs/components-rn were installed successfully.
install-peerdeps v3.0.3
Installing peerdeps for @tarojs/router-rn@3.5.7-alpha.8.
yarn add @react-native-masked-view/masked-view@~0.2.7 react-native-gesture-handler@~2.8.0 react-native-safe-area-context@~4.4.1 react-native-screens@^3.18.2

SUCCESS The peerDeps of @tarojs/router-rn were installed successfully.
Scanning for pods...
1.14.3
> pod install
Using Expo modules
[Expo] Enabling modular headers for pod ExpoModulesCore
[Expo] Enabling modular headers for pod ReactCommon/turbomodule/core

[!] Invalid `Podfile` file: undefined method `exists?' for File:Class.

 #  from /Users/xxxx/Git/taro/test/taro-native-shell/ios/Podfile:9
 #  -------------------------------------------
 #  target 'taroDemo' do
 >    use_expo_modules!
 #    post_integrate do |installer|
 #  -------------------------------------------
Couldn't install Pods. Updating the Pods project and trying again...
> pod install --repo-update
Using Expo modules
[Expo] Enabling modular headers for pod ExpoModulesCore
[Expo] Enabling modular headers for pod ReactCommon/turbomodule/core

[!] Invalid `Podfile` file: undefined method `exists?' for File:Class.

 #  from /Users/xxxx/Git/taro/test/taro-native-shell/ios/Podfile:9
 #  -------------------------------------------
 #  target 'taroDemo' do
 >    use_expo_modules!
 #    post_integrate do |installer|
 #  -------------------------------------------
Couldn't install Pods. Updating the Pods project and trying again...
Command `pod install` failed.
└─ Cause: Invalid `Podfile` file: undefined method `exists?' for File:Class.

 #  from /Users/xxxx/Git/taro/test/taro-native-shell/ios/Podfile:9
 #  -------------------------------------------
 #  target 'taroDemo' do
 >    use_expo_modules!
 #    post_integrate do |installer|
 #  -------------------------------------------

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

该错误经过排查系Mac os下的ruby版本导致,经过chatgpt的建议,安装rvm以实现ruby环境切换。

RVM安装

执行RVM安装命令:

\curl -sSL https://get.rvm.io | bash -s stable

安装完成后,加载RVM脚本:

source /Users/xxxx/.rvm/scripts/rvm

验证安装:

rvm --version

Ruby安装

接下来安装ruby-2.7.5;

rvm install "ruby-2.7.5"

安装时报错:

Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/14.0/arm64/ruby-2.7.5.tar.bz2
Checking requirements for osx.
Certificates bundle '/opt/homebrew/etc/openssl@1.1/cert.pem' is already up to date.
Requirements installation successful.
ruby-2.7.5 - #configure
ruby-2.7.5 - #download
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0 14696    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (22) The requested URL returned error: 404
The requested url does not exist(22): 'https://rvm_io.global.ssl.fastly.net/binaries/osx/14.0/arm64/ruby-2.7.5.tar.bz2?rvm=1.29.12'
Checking fallback: ftp://rvm_io.global.ssl.fastly.net/binaries/osx/14.0/arm64/ruby-2.7.5.tar.bz2?rvm=1.29.12
Checking fallback: https://www.mirrorservice.org/sites/rvm_io.global.ssl.fastly.net/binaries/osx/14.0/arm64/ruby-2.7.5.tar.bz2?rvm=1.29.12
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (22) The requested URL returned error: 404
The requested url does not exist(22): 'https://www.mirrorservice.org/sites/rvm_io.global.ssl.fastly.net/binaries/osx/14.0/arm64/ruby-2.7.5.tar.bz2?rvm=1.29.12'
Failed download
Downloading https://rvm_io.global.ssl.fastly.net/binaries/osx/14.0/arm64/ruby-2.7.5.tar.bz2 failed.
Mounting remote ruby failed with status 2, trying to compile.
Checking requirements for osx.
Certificates bundle '/opt/homebrew/etc/openssl@1.1/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/xxxx/.rvm/rubies/ruby-2.7.5, this may take a while depending on your cpu(s)...
ruby-2.7.5 - #downloading ruby-2.7.5, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 14.1M  100 14.1M    0     0  6315k      0  0:00:02  0:00:02 --:--:-- 6324k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.7.5 - #extracting ruby-2.7.5 to /Users/xxxx/.rvm/src/ruby-2.7.5 - please wait
ruby-2.7.5 - #configuring - please wait
ruby-2.7.5 - #post-configuration - please wait
ruby-2.7.5 - #compiling - please wait
Error running '__rvm_make -j10',
please read /Users/xxxx/.rvm/log/1700817199_ruby-2.7.5/make.log

There has been an error while running make. Halting the installation.

问过GPT后说是openSSL的版本问题。

安装openSSL@1.1

brew install openssl@1.1

安装完成后,指定openSSL版本再安装:

rvm install ruby-2.7.5 --with-openssl-dir=$(brew --prefix openssl@1.1)

继续报错,但是错误日志不同,是在install过程中出现错误。

修复openSSL路径

问了GPT提供了一个方案:

export LDFLAGS="-L$(brew --prefix openssl@1.1)/lib"
export CPPFLAGS="-I$(brew --prefix openssl@1.1)/include"
export PKG_CONFIG_PATH="$(brew --prefix openssl@1.1)/lib/pkgconfig"

执行后,重新安装:

rvm reinstall ruby-2.7.5 --with-openssl-dir=$(brew --prefix openssl@1.1)

若提示未安装,则可修改reinstall为install。

安装成功后,切换RVM版本:

rvm use 2.7.5

最后再次执行yarn upgradePeerdeps ,执行成功。


评论