如何解决 React Native 中出现“folly/Portability.h”和“File .../main.jsbundle 不存在”的问题?

Posted

技术标签:

【中文标题】如何解决 React Native 中出现“folly/Portability.h”和“File .../main.jsbundle 不存在”的问题?【英文标题】:how to solve the problem of "folly/Portability.h" and "File .../main.jsbundle does not exist" in React Native? 【发布时间】:2019-04-22 22:15:25 【问题描述】:

当我想编译我的 ios 应用程序以进行生产时,出现以下错误:'folly/Portability.h' file not foundecho 'error:this File .../main.jsbundle does not exist. This must be a bug with 我已经在网上搜索了解决这个问题,但我无法解决它

这里是 react-native 的信息:

  React Native Environment Info:
System:
  OS: macOS 10.14.4
  CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Memory: 38.35 MB / 8.00 GB
  Shell: 3.2.57 - /bin/bash
Binaries:
  Node: 10.15.0 - /usr/local/bin/node
  npm: 6.9.0 - /usr/local/bin/npm
  Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
  iOS SDK:
    Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
  android SDK:
    API Levels: 21, 22, 24, 25, 26, 27, 28
    Build Tools: 25.0.0, 26.0.0, 26.0.2, 26.0.3, 27.0.1, 27.0.3, 28.0.3
    System Images: android-18 | Google APIs Intel x86 Atom, android-19 | Google APIs Intel x86 Atom, android-22 | Google APIs Intel x86 Atom, android-24 | Google APIs Intel x86 Atom, android-25 | Google APIs ARM EABI v7a, android-25 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom
IDEs:
  Android Studio: 3.4 AI-183.5429.30.34.5452501
  Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
  react: 16.6.3 => 16.6.3 
  react-native: ^0.59.6 => 0.59.6 
npmGlobalPackages:
  react-native-cli: 2.0.1
  react-native-rename: 2.4.1

这是我的 Pod 的配置

platform :ios, '9.0'

target 'AppXYZ' do

  # Pods for AppXYZ

  # Required by RNFirebase
  pod 'Firebase/Core', '~> 5.15.0'
  pod 'Firebase/Messaging', '~> 5.15.0'

  pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'
  pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo'

  pod 'React', :path => '../node_modules/react-native'
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
  pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler'
  # Third party deps podspec link
  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 'AppXYZTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

为了解决第一个问题('folly/Portability.h')我在网上找到了这个(但它不起作用)

      # Third party deps podspec link
  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'

为了解决第二个问题,我发现了这个: react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios/assets 但它不起作用,它会为我生成另一个错误:

Loading dependency graph...error jest-haste-map: Haste module naming collision:
  Duplicate module name: react-native
  Paths: .../ios/Pods/React/package.json collides with .../node_modules/react-native/package.json

这些行将不得不解决这个问题(但它没有解决)

  pod 'React', :path => '../node_modules/react-native'
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
  pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler'

有人可以帮助我,因为我被困住了

【问题讨论】:

在同一条船上使用来自他们 cli 的全新 react-native 应用程序。添加了手势处理程序 pod,突然需要调整 react-native:***.com/questions/50805753/…。运行“解决第二个问题”成功完成,但实际运行应用程序失败,仍然出现愚蠢错误。 【参考方案1】:

只需从 Pods 项目设置中将 Folly 文件夹拖放到 Build Settings 选项卡中的“Header Search Paths”框并重新构建。见下图

search header path setting

【讨论】:

感谢您的回答,但我解决了,我创建了一个新项目,然后复制并粘贴。我知道,这不是最好的解决方案。

以上是关于如何解决 React Native 中出现“folly/Portability.h”和“File .../main.jsbundle 不存在”的问题?的主要内容,如果未能解决你的问题,请参考以下文章

解决react-native 打包apk 图片 不出现问题

解决 React-Native 加载数据页面卡顿问题

react native 远程js调试出现卡顿并出现黄色提示的解决方法

配置reactNative(RN)过程中 出现react-native:command not found 和 zsh: command not found: react-native

React-Native添加依赖包后出现Native module cannot be null!的解决办法

无法从“App.js”解析“@react-navigation/native”-React Native + 如何解决?