React - 在 chrome 中调试时,出现“文档未定义”错误

Kai*_*sen 5 javascript debugging google-chrome react-native

我正在尝试在 Chrome 中调试 React Native iOS 项目,我得到一个堆栈跟踪,说明document is not defined. 当我禁用 chrome 调试时,该应用程序工作正常。我在 package.json 中使用 react-native 0.14.2。当我尝试为任何示例应用程序启用调试时,我在 chrome 中遇到相同的错误。我只是从 github 上查看了 react 框架,所以我没有使用“react native”命令。任何想法这里可能有什么问题?下面是启用“Chrome 调试”时我的屏幕外观的红色框。反应下面的红盒图像。谢谢!

当我在 chrome 调试中检查堆栈跟踪时,这是它抛出的行:

require("react-native/Examples/ViroSample/ViroSampleApp.ios.js");
Run Code Online (Sandbox Code Playgroud)

这是完整的堆栈跟踪:

文档未定义
处理异常@ExceptionsManager.js:63
handleError @InitializeJavaScriptAppEngine.js:80
ErrorUtils.reportFatalError @ error-guard.js:28
requireImpl @require.js:31
require @require.js:21
(anonymousfunction)@ViroSampleApp。 ios.js.js:1 messageHandlers.executeApplicationScript
@ debuggerWorker.js:18
onmessage @ debuggerWorker.js:42


更新
违规代码似乎是 ReactErrorUtils.js 中的以下内容,它是 react-haste 模块的一部分:

if (__DEV__) {
  /**
   * To help development we can get better devtools integration by simulating a
   * real browser event.
   */
  if (typeof window !== 'undefined' &&
      typeof window.dispatchEvent === 'function' &&
      typeof Event === 'function') {
    var fakeNode = document.createElement('react');
    ReactErrorUtils.invokeGuardedCallback = function(name, func, a, b) {
      var boundFunc = func.bind(null, a, b);
      fakeNode.addEventListener(name, boundFunc, false);
      fakeNode.dispatchEvent(new Event(name));
      fakeNode.removeEventListener(name, boundFunc, false);
    };
  }
}
Run Code Online (Sandbox Code Playgroud)

Dan*_*idt 0

这是以前(0.14.2 之前)react-native 版本中的一个已知错误,如果您最近更新了重新安装节点模块 ( rm -rf node_modules && npm install) 并清理加速缓存 ( rm -rf $TMPDIR/react-*) 应该可以修复此问题。