javascript - React - 在 chrome 中调试时,出现 'document not defined' 错误

标签 javascript google-chrome debugging react-native

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

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

require("react-native/Examples/ViroSample/ViroSampleApp.ios.js");

这是完整的堆栈跟踪:

Document is not defined
handle Exception @ 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


更新
有问题的代码似乎是 React-haste 模块一部分的 ReactErrorUtils.js 中的以下代码:

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);
    };
  }
}

最佳答案

这是一个已知错误 in former (pre 0.14.2) react-native versions ,如果你最近更新了重新安装节点模块(rm -rf node_modules && npm install)和清理加速缓存(rm -rf $TMPDIR/react-*)应该修复这个。

关于javascript - React - 在 chrome 中调试时,出现 'document not defined' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34078963/

相关文章:

javascript - 与抛出错误相反,ES6函数的默认参数如何返回未定义的?

javascript - jQuery addClass() 返回意外结果

javascript - 添加后使用 jQuery 将 div 自动滚动到底部

javascript - 添加元素后触发 JavaScript 代码

javascript - Chrome 扩展消息传递 : response not sent

javascript - 无法让 JavaScript 代码在 Firefox 上运行

javascript - 变量不可能设置为 "undefined"

dll - 尽管加载了私有(private) pdb 文件,WinDBG 不显示源代码行

java - 由 : android. view.InflateException : Binary XML file line #9: Error inflating class android. widget.ImageView 引起

javascript - .NET 中的 js 包含文件