1
window.onerror = function(message, filename, lineno, colno, error) {
    console.log(error.stack);
};

Without reactjs, everything is fine. I can get the stack.

With reactjs I get the following:

Uncaught TypeError: Cannot read property 'stack' of null
window.onerror                              @ index.html:9
ReactErrorUtils.invokeGuardedCallback       @ ReactErrorUtils.js:71
executeDispatch                             @ EventPluginUtils.js:79
executeDispatchesInOrder                    @ EventPluginUtils.js:102
executeDispatchesAndRelease                 @ EventPluginHub.js:43
executeDispatchesAndReleaseTopLevel         @ EventPluginHub.js:54
forEachAccumulated                          @ forEachAccumulated.js:23
EventPluginHub.processEventQueue            @ EventPluginHub.js:259
runEventQueueInBatch                        @ ReactEventEmitterMixin.js:18
ReactEventEmitterMixin.handleTopLevel       @ ReactEventEmitterMixin.js:34
handleTopLevelWithoutPath                   @ ReactEventListener.js:93
handleTopLevelImpl                          @ ReactEventListener.js:73
Mixin.perform                               @ Transaction.js:136
ReactDefaultBatchingStrategy.batchedUpdates @ ReactDefaultBatchingStrategy.js:62
batchedUpdates                              @ ReactUpdates.js:94
ReactEventListener.dispatchEvent            @ ReactEventListener.js:204

In file ReactErrorUtils.js:

if (process.env.NODE_ENV !== 'production') {
  /**
   * To help development we can get better devtools integration by simulating a
   * real browser event.
   */
  if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
    var fakeNode = document.createElement('react');
    ReactErrorUtils.invokeGuardedCallback = function (name, func, a, b) {
      var boundFunc = func.bind(null, a, b);
      var evtType = 'react-' + name;
      fakeNode.addEventListener(evtType, boundFunc, false);
      var evt = document.createEvent('Event');
      evt.initEvent(evtType, false, false);
      // Line 71
      fakeNode.dispatchEvent(evt);
      fakeNode.removeEventListener(evtType, boundFunc, false);
    };
  }
}

It seems that reactjs hijack the events, and dispatch new event which lacks the error argument.

How can I get stack from error?

2 Answers 2

1

Although this should not happen, it could be React's internally used class names conflicting with the class names of your application. I Googled the problem and found a forum where someone fixed this exact problem by changing his class names.

React has been known to give errors which are misleading or give surprisingly little detail (i.e. Invariant Error)

Sign up to request clarification or add additional context in comments.

1 Comment

Errors should have a stack. see below: embed.plnkr.co/kVAO57uMS3lVuqDuo9SM
1

New updates from React 16.

There is a new life cycle method componentDidCatch which is triggered when there is an error inside the child components.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.