Closed pi0 closed 8 months ago
@cany748 Thanks a lot for the fix!
I'm trying to import consola to log requests received by nitro but I still have an unformatted version of consola, what's the right way to import it?
For now I'm doing it this way:
import { consola } from 'consola'
consola.box({
title: `Request at ${time}`,
message: `[${event.method}] ${event.path}`
})
Thanks in advance for your advice
@cany748 Thanks a lot for the fix!
I'm trying to import consola to log requests received by nitro but I still have an unformatted version of consola, what's the right way to import it?
For now I'm doing it this way:
import { consola } from 'consola' consola.box({ title: `Request at ${time}`, message: `[${event.method}] ${event.path}` })
Thanks in advance for your advice
Do you need the full version of consola in production mode? Try this:
// nitro.config.ts
export default defineNitroConfig({
imports: { imports: [{ name: "consola", from: "consola" }] },
unenv: { alias: { consola: "consola" } },
});
And use the auto-imported consola
.
@cany748 Thanks a lot for the fix! I'm trying to import consola to log requests received by nitro but I still have an unformatted version of consola, what's the right way to import it? For now I'm doing it this way:
import { consola } from 'consola' consola.box({ title: `Request at ${time}`, message: `[${event.method}] ${event.path}` })
Thanks in advance for your advice
Do you need the full version of consola in production mode? Try this:
// nitro.config.ts export default defineNitroConfig({ imports: { imports: [{ name: "consola", from: "consola" }] }, unenv: { alias: { consola: "consola" } }, });
And use the auto-imported
consola
.
@cany748 Thank you very much, it works! (I had to put this config in the nitro key of nuxt.config.ts because nuxt warned me that nitro.config.ts cannot be used with nuxt)
I only need consola in dev, will this method be only effetive in dev or also in production (after build)?
I have a second question, why do we have to add these options to access consola when you've made the fix above which seemed to no longer mock the full build of consola in dev?
I only need consola in dev, will this method be only effetive in dev or also in production (after build)?
The full version of consola will be available in Production mode
I have a second question, why do we have to add these options to access consola when you've made the fix above which seemed to no longer mock the full build of consola in dev?
try updating the dependencies
Context: https://github.com/unjs/nitro/issues/1761
We automatically use lighter build of consola for production but for development, we can keep using fancy logger.