React Native-iOS-无效的“ Podfile”文件:nil:NilClass

时间:2019-10-16 23:41:31

标签: ios xcode react-native

我刚开始使用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 / 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文件的东西是如何工作的!我试图删除完成重置的文件夹。除此之外,我不知道错误消息的含义。

4 个答案:

答案 0 :(得分:6)

当您CD到ios文件夹并运行“ pod install”时,会发生此错误 这是因为您通过

添加了新的react native模块

npm -i

代替纱线

添加纱线

要解决此问题,只需转到package.json所在的主react native项目文件夹,然后再次运行以下命令

清理纱线缓存

添加纱线

然后尝试cd到ios文件夹并运行“ pod install”,将没有更多错误。希望这可以帮助遇到同样问题的其他人。

答案 1 :(得分:1)

此答案很好地解决了我的问题:

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

快乐的编码!

答案 2 :(得分:0)

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

答案 3 :(得分:0)

在Flutter上也可能发生此错误,以使用下面的命令解决此问题

describe('PDF manipulation', () => {
    it('Manipulated test file should not be null', async () => {
        fs.readFile('test.pdf', (async function (err, data){
            if (err) throw err;
            let manipulatedPdf = await manipulate_file(data);
            expect(manipulatedPdf).to.be.not.null;
        }).catch(error => console.log(error)));
    });
});