Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
randreu28 opened this issue Nov 6, 2023 · 2 comments
Open

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

randreu28 opened this issue Nov 6, 2023 · 2 comments

Comments

@randreu28
Copy link

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
Copy link

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
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants