bugsnag-js: TypeError: Cannot read property 'createErrorBoundary' of undefined

Following the Bugsnag Docs to config the project and run got this error from: const ErrorBoundary = Bugsnag.getPlugin('react').createErrorBoundary(React);

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 7
  • Comments: 24 (10 by maintainers)

Most upvoted comments

Can you please reference this in your documentation until this is released? I just spend 2-3 hours thinking I setup my app was wrong, meticulously looking at the docs, but it looks like this feature just doesn’t work at all with recent versions of react-native and bugsnag, even with the base case in the documentation.

Hey @adkenyon, we’re looking into a fix for this notifier side. But, in the meantime you can guard against this by checking whether the getPlugin() call returns undefined, and in these cases point your application to a no-op ErrorBoundary, for example:

class NoopErrorBoundary extends React.Component {
    // define your Noop Error Boundary here
}

var ErrorBoundary;
if (typeof Bugsnag.getPlugin('react') === 'undefined') {
    ErrorBoundary = NoopErrorBoundary;
} else {
    ErrorBoundary = Bugsnag.getPlugin('react').createErrorBoundary(React);
}

// use the ErrorBoundary as normal

When running without the debugger, Bugsnag will continue as normal with the Bugsnag error boundary.

That does look like a bug, although one that would only have an impact when the debugger is attached.

We’ll look into whether this can be resolved in a future release.

@xander-jones thank you for the workaround!

@duzliang The issue is that you’re calling Bugsnag.getPlugin('react') before you call Bugsnag.start().

Bugsnag.start() must be called before any other method so you’ll need to move it out of the constructor of your component.