25

I upgraded my React version from 0.12.2 to 0.13.2 and my React-Router from 0.12.4 to 0.13.2. Doing just those two upgrades and nothing else, I now get the following error when I load my webpage/app:

Uncaught TypeError: Cannot read property '_currentElement' of null

Any ideas what might be causing this? I have seem some references to a potential React-Router bug, but nothing definitive.

The specific line that causes the error is:

ReactRef.detachRefs(internalInstance, internalInstance._currentElement);

Update 1: I also just upgraded reactify from version 1.0.0 to 1.1.0 and react-router-bootstrap (which I'm not actually using yet) from 0.9.1 to 0.13.0 based on @BinaryMuse's comments - no change.

Update 2: After further testing, I have narrowed this down to an issue with react-d3. Disabling the react-d3 code from my site causes the error to go away. I am removing the routing code to make the post more concise since I am now fairly confident that react-router is not causing this issue.

Update 3: Thanks to @CoryDanielson for creating the new tag for react-d3.

package.json

{
  "author": "me",
  "name": "my project",
  "description": "my awesome project",
  "version": "0.1.0",
  "dependencies": {
    "bootstrap": "^3.3.2",
    "d3": "^3.5.5",
    "font-awesome": "^4.3.0",
    "jquery": "^2.1.3",
    "react": "^0.13.2",
    "react-bootstrap": "^0.21.0",
    "react-d3": "^0.3.1",
    "react-router": "^0.13.2",
    "react-router-bootstrap": "~0.13.0",
    "reflux": "^0.2.6",
    "uuid": "^2.0.1"
  },
  "devDependencies": {
    "browser-sync": "^2.2.2",
    "browserify": "^9.0.3",
    "del": "^1.1.1",
    "envify": "^3.4.0",
    "gulp": "^3.8.11",
    "gulp-css-url-adjuster": "^0.2.3",
    "gulp-jshint": "^1.9.2",
    "gulp-minify-css": "^0.5.1",
    "gulp-sourcemaps": "^1.5.0",
    "gulp-uglify": "^1.1.0",
    "gulp-util": "^3.0.4",
    "gulp-watch": "^4.1.1",
    "reactify": "~1.1.0",
    "vinyl-buffer": "^1.0.0",
    "vinyl-source-stream": "^1.0.0",
    "watchify": "^2.4.0"
  },
  "browserify": {
    "transform": [
      [
        "reactify",
        {
          "es6": false
        }
      ]
    ]
  },
}
4

6 回答 6

12

我已经想通了。这归结为react-d3中的render函数存在问题。该函数通过对数据数组的第一个元素进行采样来检查数据的类型。但是,它不提供任何检查以查看数据数组是否为空。linechart/DataSeries

我以前看到过错误,LineChart形式为

Uncaught TypeError: Cannot read property 'x' of undefined

但是,我忽略了它们,因为它们是访问错误并且没有阻止应用程序运行。React 中的某些内容必须从 v0.12.4 更改为 v.0.13.2,以至于这些以前无害的错误现在正在破坏。我阅读了 v0.13.0、v0.13.1 和 v.0.13.2 的发行说明,但没有发现任何说明为什么会发生这个新错误。我没有时间查看代码差异。

我没有连接这两个错误,因为部分LineChart仍然抛出Uncaught TypeError: Cannot read property 'x' of undefined,所以我只是假设该Uncaught TypeError: Cannot read property '_currentElement' of null错误是由升级引起的新错误,并且正在掩盖额外的无法读取 x 错误。

我将很快向 react-d3 提交一个 pull-request 来纠正这个问题。谢谢大家的帮助。

更新: 这是拉取请求

于 2015-04-22T18:59:04.813 回答
3

我在 0.13.2 中遇到了同样的问题,但是,我的错误原因和解决方案有点不同:

错误归结为我的 npm 版本。自从升级(现在是 2.8.4)并运行 npm update -g npm 以来,我一直在使用 npm 2.1.4,我能够在不触及我的 package.json 或其他任何东西的情况下让一切正常工作。

让我知道这是否适合你!

于 2015-04-28T22:55:36.750 回答
3

如果它可以帮助我使用错误事件名称道具(onItemChange 而不是 onChange)在 Material-UI DropDownMenu 组件中遇到同样的错误。

    <DropDownMenu menuItems={menuItems} onChange={this._onItemClick}/>

使用正确的事件道具名称为我解决了这个问题。

于 2015-05-23T20:50:00.060 回答
2

花了一整天的时间来解决这个问题,最终是由于console.warn来自 React.PropTypes 验证失败的调用。一旦我们修复了这些 PropType 问题,IE9 又开始工作了。(我们的问题来自具有未定义值而不是字符串的数据,以及在某些 JSX 上使用 key 属性的建议)

HTML Boilerplate 对此有一个解决方案,每个人都应该使用它: https ://github.com/h5bp/html5-boilerplate/blob/master/src/js/plugins.js#L2-L22

// Avoid `console` errors in browsers that lack a console.
(function() {
    var method;
    var noop = function () {};
    var methods = [
        'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
        'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
        'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
        'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
    ];
    var length = methods.length;
    var console = (window.console = window.console || {});

    while (length--) {
        method = methods[length];

        // Only stub undefined methods.
        if (!console[method]) {
            console[method] = noop;
        }
    }
}());

与此相同的问题:为什么 JavaScript 仅在 IE 中打开开发人员工具一次后才能工作?

于 2015-05-01T23:01:01.387 回答
0

添加“babel-polyfill”为我解决了 IE11 中的问题

于 2016-12-08T12:11:25.593 回答
-1

当我的 app.jsx 文件引用 List 组件并且我忘记将它包含在其中时,我收到了这个错误

var List = require('./list');
于 2016-02-17T03:02:45.910 回答