追踪React.js错误原因

时间:2015-07-29 19:33:38

标签: javascript node.js reactjs typeerror

我在React.js中出现错误,只会在非常特殊的情况下发生。

当我创建错误时,错误会打印到Chrome中的JS控制台,但它并不特别具有语义性。

用于跟踪React.js上下文中的违规行或函数的最佳做法,提示和技巧是什么?

由于10247前缀,第61行的值似乎没有多大意义 - 这是否真的是指第61行,或者这只是因为源代码图或其他东西而导致的垃圾?

Unhandled rejection TypeError: Cannot set property 'value' of undefined
    at http://localhost:4000/js/analytics.js:10247:61
    at Array.forEach (native)
    at http://localhost:4000/js/analytics.js:10246:16
    at Array.forEach (native)
    at updatePoints (http://localhost:4000/js/analytics.js:10245:29)
    at module.exports.createClass.classData.componentWillReceiveProps (http://localhost:4000/js/analytics.js:10195:9)
    at 43.ReactCompositeComponentMixin.updateComponent (http://localhost:4000/js/vendor.js:42736:14)
    at 82.ReactPerf.measure.wrapper [as updateComponent] (http://localhost:4000/js/vendor.js:49431:21)
    at 43.ReactCompositeComponentMixin.receiveComponent (http://localhost:4000/js/vendor.js:42623:10)
    at Object.89.ReactReconciler.receiveComponent (http://localhost:4000/js/vendor.js:50301:22)
    at Object.__REACT_INSPECTOR_RUNTIME__0_13_1.React.ReactReconciler.receiveComponent (<anonymous>:118:43)
    at 43.ReactCompositeComponentMixin._updateRenderedComponent (http://localhost:4000/js/vendor.js:42865:23)
    at 43.ReactCompositeComponentMixin._performComponentUpdate (http://localhost:4000/js/vendor.js:42843:10)
    at 43.ReactCompositeComponentMixin.updateComponent (http://localhost:4000/js/vendor.js:42759:12)
    at 82.ReactPerf.measure.wrapper [as updateComponent] (http://localhost:4000/js/vendor.js:49431:21)
    at 43.ReactCompositeComponentMixin.receiveComponent (http://localhost:4000/js/vendor.js:42623:10)

提前感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

Yupe,将您的代码拆分为单个文件,并尝试使用browserify(或webpack)并将调试标志设置为true,以便将您的大文件映射到源图并简化Chrome和朋友的调试。

点击此处查看我当前的筹码:

https://github.com/coma/domno?files=1

答案 1 :(得分:0)

事实证明,这是React.js中的对帐问题。

React主要使用启发式方法来决定在更新时重新渲染的内容,而react-chartjs库并没有很好地发挥作用。

可在此处找到更多信息:https://facebook.github.io/react/docs/reconciliation.html

我使用的修复方法主要是清除传递给图表的状态数据并强制更新,从而使React重新渲染整个元素:

this.state.countries = {
  labels: []
}

this.forceUpdate()