ReferenceError:找不到变量__fbBatchedBridge

时间:2016-03-23 23:21:30

标签: android react-native

编辑:值得注意的是我现在正在Android上开发

我的ReactNative应用程序出现__fbBatchedBridge错误。问题不是无法连接到打包者(证据如下)。当我安装了一堆软件包进行测试时,问题就开始了,但即使我还原了,也删除了node_modules,并且npm install它仍然存在。

的package.json

{
  "name": "MyApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "log": "adb logcat *:S ReactNative:V ReactNativeJS:V"
  },
  "dependencies": {
    "events": "^1.1.0",
    "react-native": "^0.18.0",
    "react-native-push-notification": "^1.0.2",
    "react-native-scrollable-tab-view": "^0.3.5",
    "react-native-webrtc": "^0.2.7",
    "react-redux": "^4.4.0",
    "redux": "^3.3.1",
    "socket.io-client": "^1.4.4"
  },
  "devDependencies": {
    "redux-devtools": "^3.1.1"
  }
}

npm开始结果

[7:19:50 PM] <START> Building Dependency Graph
[7:19:50 PM] <START> Crawling File System
[7:19:50 PM] <START> Loading bundles layout
[7:19:50 PM] <END>   Loading bundles layout (0ms)

React packager ready.

[7:19:53 PM] <START> request:/index.android.bundle?platform=android&dev=true
[7:19:53 PM] <START> find dependencies
[7:19:56 PM] <END>   Crawling File System (5686ms)
[7:19:56 PM] <START> Building in-memory fs for JavaScript
[7:19:56 PM] <END>   Building in-memory fs for JavaScript (346ms)
[7:19:56 PM] <START> Building in-memory fs for Assets
[7:19:56 PM] <END>   Building in-memory fs for Assets (322ms)
[7:19:56 PM] <START> Building Haste Map
[7:19:56 PM] <START> Building (deprecated) Asset Map
[7:19:57 PM] <END>   Building (deprecated) Asset Map (87ms)
[7:19:57 PM] <END>   Building Haste Map (452ms)
[7:19:57 PM] <END>   Building Dependency Graph (6811ms)
[7:19:57 PM] <END>   find dependencies (4018ms)
[7:19:57 PM] <START> transform
transforming [========================================] 100% 549/549
[7:20:00 PM] <END>   transform (3417ms)
[7:20:00 PM] <END>   request:/index.android.bundle?platform=android&dev=true (7463ms)

正如您所看到的,打包器打包并将捆绑包发送给Genymotion,然后引发错误。

3 个答案:

答案 0 :(得分:1)

此问题已在较新版本的React Native中修复。我建议你把你的版本升级到0.22

但是,如果您正在寻找临时解决方案,而不是node_modules/react-native/packager/packager.sh

替换

if [[ "$PLATFORM_NAME" = "iphonesimulator" ]]; then
  echo "Skipping bundling for Simulator platform"
  exit 0;
fi

#    if [[ "$PLATFORM_NAME" = "iphonesimulator" ]]; then        
#      echo "Skipping bundling for Simulator platform"      
#      exit 0;      
#    fi

答案 1 :(得分:0)

在AppDelegate.m文件中,我们将使用:

jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];

而不是:

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

它对我有用。

答案 2 :(得分:0)

从终端:

adb shell input keyevent 82

Genymotion打开开发菜单,转到开发设置

然后:adb shell input text <your IPv4 adress>:8081

最后:

adb reverse tcp:8081 tcp:8081