如何修复安装 React Native Pod 时“没有将 nil 隐式转换为字符串”问题

问题描述 投票:0回答:1

我将 React Native 从 0.72 升级到 0.73.8,但是当我尝试使用 pod install 安装 pod 时,出现以下错误:

Downloading dependencies
Generating Pods project
Setting USE_HERMES build settings
Setting REACT_NATIVE build settings
[!] An error occurred while processing the post-install hook of the Podfile.

no implicit conversion of nil into String

/Users/francescoclementi/Documents/develop/parkinglesscustomer/node_modules/react-native/scripts/cocoapods/utils.rb:130:in `join'
/Users/francescoclementi/Documents/develop/parkinglesscustomer/node_modules/react-native/scripts/cocoapods/utils.rb:130:in `block (2 levels) in set_node_modules_user_settings'
/Users/francescoclementi/Documents/develop/parkinglesscustomer/node_modules/react-native/scripts/cocoapods/utils.rb:129:in `each'
/Users/francescoclementi/Documents/develop/parkinglesscustomer/node_modules/react-native/scripts/cocoapods/utils.rb:129:in `block in set_node_modules_user_settings'
/Users/francescoclementi/Documents/develop/parkinglesscustomer/node_modules/react-native/scripts/cocoapods/utils.rb:128:in `each'
/Users/francescoclementi/Documents/develop/parkinglesscustomer/node_modules/react-native/scripts/cocoapods/utils.rb:128:in `set_node_modules_user_settings'
/Users/francescoclementi/Documents/develop/parkinglesscustomer/node_modules/react-native/scripts/react_native_pods.rb:307:in `react_native_post_install'
/Users/francescoclementi/Documents/develop/parkinglesscustomer/ios/Podfile:55:in `block (2 levels) in from_ruby'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-core-1.15.2/lib/cocoapods-core/podfile.rb:196:in `post_install!'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:1013:in `run_podfile_post_install_hook'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:1001:in `block in run_podfile_post_install_hooks'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/user_interface.rb:149:in `message'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:1000:in `run_podfile_post_install_hooks'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:337:in `block (2 levels) in create_and_save_projects'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/installer/xcode/pods_project_generator/pods_project_writer.rb:61:in `write!'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:336:in `block in create_and_save_projects'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/user_interface.rb:64:in `section'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:315:in `create_and_save_projects'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:307:in `generate_pods_project'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:183:in `integrate'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:170:in `install!'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/command/install.rb:52:in `run'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/lib/cocoapods/command.rb:52:in `run'
/Users/francescoclementi/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/cocoapods-1.15.2/bin/pod:55:in `<top (required)>'
/Users/francescoclementi/.rbenv/versions/2.7.4/bin/pod:23:in `load'
/Users/francescoclementi/.rbenv/versions/2.7.4/bin/pod:23:in `<main>'

这是我的 pod 文件:

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!


def share_pods (target_name)
  # If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
  # because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
  #
  # To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
  # ```js
  # module.exports = {
  #   dependencies: {
  #     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
  # ```
  flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

  linkage = ENV['USE_FRAMEWORKS']
  if linkage != nil
    Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
    use_frameworks! :linkage => linkage.to_sym
  end

  target target_name do

    $config = use_native_modules!

    use_frameworks! :linkage => :static
    $RNFirebaseAsStaticFramework = true

    use_react_native!(
      :path => $config[:reactNativePath],
      # Enables Flipper.
      #
      # Note that if you have use_frameworks! enabled, Flipper will not work and
      # you should disable the next line.
      # :flipper_configuration => flipper_config,
      # An absolute path to your application root.
      :app_path => "#{Pod::Config.instance.installation_root}/.."
    )
  end
end

share_pods('target1')
share_pods('target1-prod') 

post_install do |installer|
  # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
  react_native_post_install(
    installer,
    $config[:reactNativePath],
    :mac_catalyst_enabled => false
  )
end

如果我删除react_native_post_install它将工作正常,但这不是正确的解决方案

ios ruby react-native rubygems cocoapods
1个回答
0
投票

执行此行时似乎出现错误

https://github.com/facebook/react-native/blob/c39538b79dbc7f84b536431ac2230d259f846e42/packages/react-native/scripts/cocoapods/utils.rb#L130

因为

$config[:reactNativePath]
nil

File.join('', '..', nil)
# TypeError: no implicit conversion of nil into String

尝试将此值显式传递为字符串

react_native_post_install(
  installer,
  'path/here',
  :mac_catalyst_enabled => false
)
© www.soinside.com 2019 - 2024. All rights reserved.