Environment
Node: 22.12.0
PNPM: 9.15.1
Reproduction
When running the following code:
import consola from 'consola';
consola.log({ date: 'string' });
the following error occurs:
Error: date.toLocaleTimeString is not a function
This error is triggered because consola expects the date field to be an instance of Date rather than a string.
Describe the bug
When invoking consola.log with an object where the date field is set to a string, the process fails at runtime. Internally, consola calls toLocaleTimeString on the date field, which only exists on Date instances. Passing a string results in the aforementioned error.
|
return opts.date ? date.toLocaleTimeString() : ""; |
Additional context
I am attempting to customize the log output by manually specifying a custom date format.
To achieve this, I passed an object with a date field set to a string (i.e., { date: 'string' }). However, this leads to a runtime error because consola expects a Date object.
It would be helpful if either the documentation clarified that only Date objects are accepted, or if consola provided support or a graceful fallback for string values.
This change would allow developers greater flexibility when customizing log output.
Logs
Environment
Node: 22.12.0
PNPM: 9.15.1
Reproduction
When running the following code:
the following error occurs:
This error is triggered because
consolaexpects thedatefield to be an instance ofDaterather than a string.Describe the bug
When invoking
consola.logwith an object where the date field is set to a string, the process fails at runtime. Internally, consola callstoLocaleTimeStringon the date field, which only exists onDateinstances. Passing a string results in the aforementioned error.consola/src/reporters/basic.ts
Line 46 in dbc239c
Additional context
I am attempting to customize the log output by manually specifying a custom date format.
To achieve this, I passed an object with a date field set to a string (i.e.,
{ date: 'string' }). However, this leads to a runtime error becauseconsolaexpects aDateobject.It would be helpful if either the documentation clarified that only Date objects are accepted, or if consola provided support or a graceful fallback for string values.
This change would allow developers greater flexibility when customizing log output.
Logs