xcode React Native - iOS -无效的'Podfile'档案:未定义nil的'[]'方法:NilClass

mfuanj7w  于 2022-11-18  发布在  React
关注(0)|答案(5)|浏览(315)

我刚刚开始使用React Native。我遵循的是官方文档中的React Native CLI快速入门。这也意味着我使用的是最新的React Native版本0.61.2
从那以后我做了一些基本的UI,在iPhone模拟器中检查结果。它在运行react-native run-ios时工作,并没有真正接触 ios/Podfile 太多。
我的问题是在我的 ios/ 文件夹中运行 pod install 总是会导致错误!这现在成为一个问题,我需要安装额外的软件包。但它已经失败了默认的Podfile!

错误消息:

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

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

ios/播客文件

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文件是如何工作的!我试图删除文件夹完成重置。更重要的是,我不知道错误信息可能意味着什么。

gajydyqb

gajydyqb1#

这个错误发生时,你的cd到ios文件夹和运行“pod安装”,是因为你添加了一个新的React Native模块
npm -i * 软件包 *
代替使用Yarn
Yarn添加 * Package *
要解决此问题,只需转到package.json所在的主react原生项目文件夹,然后再次运行以下命令
Yarn缓存清理器
Yarn添加 * Package *
然后尝试cd到ios文件夹,运行“pod安装”,就不会有更多的错误了。希望这能帮助其他也面临同样问题的人。

oalqel3c

oalqel3c2#

这个回答很好地解决了我的问题:
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
快乐编码!

w8f9ii69

w8f9ii693#

经过半天的尝试,每一个解决方案,最后,我更换两者

  • react-native
  • @react-native-community

文件夹从另一个RN 0.63项目到node_modules和它的解决。也许我的缓存没有被正确删除或替换。

yvfmudvl

yvfmudvl4#

在我的例子中,我不小心在我的iOS文件夹中创建了一个package.json。这似乎混淆了react原生版本。我删除了我的iOS文件夹中的package.json,将package.json留在根项目文件夹中,一切正常。

s4n0splo

s4n0splo5#

  • "@react-native-community/cli-platform-ios": "3.0.0"添加到package.json文件中,并在主目录中运行npm install
  • 然后执行cd ios,再执行pod install

相关问题