unjs / consola

🐨 Elegant Console Logger for Node.js and Browser
Other
6k stars 175 forks source link

Consola does not work on the server in Next.js 14 #257

Open randreu28 opened 10 months ago

randreu28 commented 10 months ago

Environment

I believe Next.js 14 uses Node v18 (LTS)

I haven't tried in Next.js 13 but I suspect it might get a similar issue

Reproduction

I created a repository to simulate the issue.

You can also check it live via this github codespace:

Describe the bug

Consola does not work well when logging in the server on Next.js 14:

image

It DOES work on the client:

image

I've tried using different imports, but I wanted to see it it was possible to use the fancy reporter with the colors :')

import consola from "consola"; //does not work
import consola from "consola/basic"; // works without the colors
import consola from "consola/browser"; // works without the colors

It might be my ignorance as to how loggers differ from browser rather than in the server, but shouldn't the server also be able to print colors?

Additional context

No response

Logs

No response

realfresh commented 10 months ago

Had the same issue. I found importing consola like this worked fine: import {createConsola} from "consola/core";

To get the same behaviour as the default export, you need to:

  1. Copy how consola is created in the default export: https://github.com/unjs/consola/blob/main/src/index.ts
  2. I couldn't find a way to import the FancyReport and BasicReport either, so I had to copy them from these files (making sure to install any extra dependencies:

Pretty sure this whole issue has something to do with this line: https://github.com/unjs/consola/blob/a440c4d4bbc39135a1514bcd78fcbaba2c571285/src/index.ts#L25C10-L25C10

randreu28 commented 10 months ago

Well, I was asking in the hopes that I don't have to copy paste the implementation of the reporters from the consola source code with only the parts that work well in my case. My issue is not the fact that there are no workarounds. It's the fact that there is a need for a workaround.

Appreciate the effort though!