React Native-iOS-无效的Podfile文件:nil:NilClass的未定义方法'[]'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了React Native-iOS-无效的Podfile文件:nil:NilClass的未定义方法'[]'相关的知识,希望对你有一定的参考价值。

我刚开始使用React Native。我遵循官方文档中的React Native CLI快速入门。这确实也意味着我是最新的React Native版本0.61.2

从那时起,我已经完成了一些基本的UI,并在iPhone模拟器中检查了结果。它在运行react-native run-ios时起作用,而不用过多地触摸ios / Podfile

我的问题正在运行ios /文件夹中的pod安装总是导致错误!现在这成为一个问题,我需要安装其他软件包。但是默认Podfile已经失败了!

错误消息:

[!] Invalid `Podfile` file: undefined method `[]' for nil:NilClass.

 #  from /Users/marcel/Projekte/WerBinIch/ios/Podfile:43
 #  -------------------------------------------
 #  
 >    use_native_modules!
 #  end
 #  -------------------------------------------

ios / Podfile

platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'WerBinIch' do
  # Pods for WerBinIch
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'


  target 'WerBinIchTests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end

我不知道该如何处理!我不知道Podfile和带有xcode文件的东西是如何工作的!我试图删除完成重置的文件夹。除此之外,我不知道错误消息可能意味着什么。

答案
react-native ios Podfile issue with "use_native_modules!"

这里是正确答案:

1-您的POD文件的顶部应包含此行

require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

2-确保您的package.json和node_module文件夹已安装此模块

cli-platform-ios/native_modules

3-如果在运行yarn install后未找到,则表明您的计算机中有旧的高速缓存node_modules,需要在重新安装该软件包之前对其进行清理。

4-清理缓存

$ yarn cache clean

5-确保您具有此文件react-native.config.js,并且其配置是有效的-并且它没有不存在的NPM软件包-此步骤是错误的最后且最主要的原因] >>

我的react-native.config.js示例

module.exports = { project: { ios: {}, android: {}, }, assets: ['./assets/fonts/'] dependencies: {}, // make sure this deps are all valid installed packages or empty if you don't need it };

6-安装节点软件包yarn install,您的Pod应该可以正常工作了!$ pod install --repo-update

快乐编码!

以上是关于React Native-iOS-无效的Podfile文件:nil:NilClass的未定义方法'[]'的主要内容,如果未能解决你的问题,请参考以下文章

React 警告:函数作为 React 子级无效

错误:对象作为 React 子项无效(找到:带有键 的对象)。改用数组

React.createElement:类型无效

React 中的 BrowserRouter 导致“无效的钩子调用”

React.createElement:类型无效(地图)

对象作为 React 子代无效(在 Internet Explorer 11 中用于 React 15.4.1)