DEV Community

Łukasz Wolnik
Łukasz Wolnik

Posted on

Cerebral Debugger in Next.js

If you are getting below error:

ReferenceError: WebSocket is not defined
    at Devtools.createSocket
Enter fullscreen mode Exit fullscreen mode

when trying to hook Cerebral Debugger up in Next.js try to refactor your bootstrap code from this:

const devTools =
  process.env.NODE_ENV === "production"
    ? null
    : {
        devtools: DevTools({
          host: "localhost:8585",
        }),
      };
Enter fullscreen mode Exit fullscreen mode

to this:

let devTools = null;

if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
  devTools = {
    devtools: DevTools({
      host: "localhost:8585",
    }),
  };
}
Enter fullscreen mode Exit fullscreen mode

Now you're be able to use Cerebral Debugger whilst still using Next.js when calling below:

export default App(({ app }) => {
  app.on("initialized", () => {
    app.getSequence("initialize")();
  });
  return {
    state,
    sequences,
    providers,
  };
}, devTools);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)