-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Doesn't work in Next.js middleware (Edge functions) #13
Comments
PS thanks for this library 😄 It's probably the most versatile of the new fast colour loggers. Great to have a package still supporting CJS too, unlike some other chalky libs 😬 |
Hello @will-stone, thank you for the issue report! Of course, your PR would be welcome too ;-) |
I'm happy to PR it, for sure. However, I'm a little worried I could break other situations. Would you be happy for me to add a failing test PR instead? I can try to set up a test that mimics Next.js middleware environment. |
Yes, please create a small repository with a reproducible problem. This will help me solve the issue faster. |
Oh sure, happy to do that instead too. The codesandbox can be a bit flaky. I'll let you know when I have a repo for you to spin up 👍 |
Here you go: https://github.com/will-stone/nextjs-ansis Thanks! 🙂 |
how can be set runtime as I set |
Ah, middleware is always run in edge mode. This is the cause of the problem. |
ok, no problem |
This is one of the reasons I've been looking at Ansis: other libraries rely on There's a Next.js issue here that started me looking at this library. The author reckons Ansis works but maybe that was an older version. |
I know, the |
can you please check the beta version |
It works! will-stone/nextjs-ansis@85e413c Thank you for this amazingly quick turnaround 🤯 This needs to be marketed to the Next.js peeps at Vercel as this lib could be their default for all logging now. |
@will-stone Thank you for the suggestion.
Many developers would benefit from having a small/fast/powerful/universal color library. I'm afraid that Next.js will reject Ansis due to its low popularity. Although chalk is also developed and maintained by one person, it is a very popular person. We can try to suggest Asisis in Next.js, but it should not be the author (me), but another developer. If I do this, it will be perceived as self-promotion/spam. |
Yeah sorry, more of a throw away comment really. I’ll put a thread in their GitHub discussions to direct people this way when looking for a color logger that supports all of Next.js 👍😊 |
@will-stone thank you :-) |
@will-stone the support for Next.js is released in the Note:In the new release is changed named import: import ansis, { red } from 'ansis'; // default and named import
ansis.red`error`;
red`error`; OLD ( import ansis from 'ansis'; // default import
import { red } from 'ansis/colors'; // named import
ansis.red`error`;
red`error`; |
can be closed the issue? |
Awesome! Thanks, yeah let's close and I'll open new issues if I find any 🙂 |
Current behaviour
When using Ansis inside Next.js's
middleware.ts
file, colours aren't enabled.Expected behaviour
Colours shown in terminal when using Ansis in a Next.js edge function.
Reproduction Example
Codesandbox
Environment
Additional context
I've narrowed this down to this line:
ansis/src/ansi-codes.js
Line 29 in 7fca74c
process.stdout
not being available in Next.js's middleware. Is thestdout && 'isTTY' in stdout
necessary if you also require the/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)
to pass?The text was updated successfully, but these errors were encountered: