bugsnag/bugsnag-js

createErrorBoundary get error "Cannot read properties of undefined (reading 'prototype')" in Nextjs 14

chiennv97fenik opened this issue · 3 comments

I'm integrate bug snap for project Nextjs 14, but I getting issue

File: layout.js

import Bugsnag from "@bugsnag/js";
import BugsnagPluginReact from "@bugsnag/plugin-react";
import React from "react";
...
Bugsnag.start({
    apiKey: "e28a53d75b1907b8076ad881d0aacdb3",
    plugins: [new BugsnagPluginReact()],
  });
 const ErrorBoundary = Bugsnag.getPlugin("react").createErrorBoundary(React);

Error: Cannot read properties of undefined (reading 'prototype')

Please Help me

Hi @chiennv97fenik

Thank you for reaching out.

It's possible that this error has been caused by a race condition when rendering a component returned from getPlugin - which may happen before calling Bugsnag.start

However we are unable to verify this without further investigation, could you please provide the full error log for the error Cannot read properties of undefined (reading 'prototype') ?

Hi @chiennv97fenik

As there hasn't been any activity here for a while, we are now closing this issue.

If you continue to experience any problems, please feel free to reopen this issue along with any additional relevant information (such as the full error log), or open a ticket with us directly by contacting support@bugsnag.com.

For future reference, I just faced this same issue today and the solution is to initialise Bugsnag in a Client component instead of a Server component. My approach was to create a client component which is rendered inside the top-most layout.tsx file of the app router, and this client component will contain all the initialisation code for Bugsnag and various other providers that are used in my application.