带有“ use_native_modules!”的react-native ios Podfile问题!

Cor*_*son 14 ios cocoapods react-native react-native-ios

在ios /目录中的我的react-native项目(react-native@0.60)中,我运行pod install并得到以下错误:

[!] Invalid `Podfile` file: no implicit conversion of nil into String.

 #  from /Users/coryrobinson/projects/hhs2/ios/Podfile:37
 #  -------------------------------------------
 #  
 >    use_native_modules!
 #  end
 #  -------------------------------------------

Run Code Online (Sandbox Code Playgroud)

我没有在此Podfile中添加或更改任何内容-它们都是react-native生成的。(我没有iOS开发经验,所以这可能是一个简单的解决方法,我只是不知道要寻找什么:-|)感谢您的帮助!

这是我的Podfile

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

target 'hhs2' do
  # Pods for hhs2
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/React'
  pod 'React-DevSupport', :path => '../node_modules/react-native/React'
  pod 'React-fishhook', :path => '../node_modules/react-native/Libraries/fishhook'
  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-RCTWebSocket', :path => '../node_modules/react-native/Libraries/WebSocket'
  pod 'RNFS', :path => '../node_modules/react-native-fs'

  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 '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 'hhs2Tests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end

target 'hhs2-tvOS' do
  # Pods for hhs2-tvOS

  target 'hhs2-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end

end
Run Code Online (Sandbox Code Playgroud)

Mea*_*bed 21

这是正确的答案:

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

require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
Run Code Online (Sandbox Code Playgroud)

2-确保您的package.jsonnode_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
};
Run Code Online (Sandbox Code Playgroud)

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

祝您编码愉快!

  • React-native.config.js 文件应该在根文件夹中还是在 ios 中? (2认同)

Vit*_*pes 9

将@react-native-community/cli-platform-ios 从 3.1.0 降级到 3.0.0 并且它起作用了。

添加

"@react-native-community/cli-platform-ios": "3.0.0"
Run Code Online (Sandbox Code Playgroud)

到 package.json。

运行 npm install 然后 pod install 让它再次工作。

  • 作品,截至 2020 年 3 月 (3认同)

jsi*_*ina 6

这是因为您的设备上的纱线版本已过时,如果您在 macOS 上,您可以通过以下链接升级/安装纱线: 这里是

请注意删除node-moduleyarn.lock归档,再次安装所有软件包,导航到ios文件夹并运行pod install.


B. *_*mad 6

验证您的package.json@react-native-community/cli-platform-ios中是否有 ,

如果你不运行:

npm install @react-native-community/cli-platform-ios

然后

cd ios && pod install


MoO*_*oOx 5

如果您正在使用

pod install --project-directory=ios
Run Code Online (Sandbox Code Playgroud)

您可能需要通过替换来调整 Podfile

use_native_modules!

use_native_modules!(".")

也许这种行为将来会得到改善,我打开了一个关于它的问题https://github.com/react-native-community/cli/issues/657