debug-js / debug

A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers
MIT License
11.12k stars 932 forks source link

Issue in Next.js #944

Closed mledwards closed 1 year ago

mledwards commented 1 year ago

I've added this debug line to the server side templatelayout.tsx of a Next.js v13.5 project, and I'm getting this error. image

Any ideas what could be causing this?

mledwards commented 1 year ago

Oh, I also have this in the next.config.js

const nextConfig = {
  env: {
    DEBUG: process.env.NODE_ENV === "development" ? "boilerplate:*" : "",
  }
};
Qix- commented 1 year ago

debug is an ESM package. Try using import.

Qix- commented 1 year ago

Going to close this unless there's something else!

mledwards commented 1 year ago

debug is an ESM package. Try using import.

I changed this to

import debugPackage from "debug"
const debug = debugPackage("boilerplate:home");

but got the same issue.

I think the problem is this line DEBUG: process.env.NODE_ENV === "development" ? "boilerplate:*" : "", line. In Next 13.4+ App Router approach it looks like I didn't need it anymore, just setting the DEBUG env var seems to work.

Thanks for the response!

jyunhanlin commented 11 months ago

https://github.com/debug-js/debug/blob/master/src/node.js#L205

It seems the code will cause Next.js to fail when using DEBUG=xxx:* npm run dev When I comment it, the issue is gone.