You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
The text was updated successfully, but these errors were encountered:
My plan is to add a check before invoking any Date instance functions (such as toLocaleTimeString).
The code would verify if the provided value is indeed a Date instance, and if it is not, it would simply do nothing.
This should prevent the error without altering the intended functionality.
Would it be acceptable for me to submit a pull request with this change?
Environment
Node: 22.12.0
PNPM: 9.15.1
Reproduction
When running the following code:
the following error occurs:
This error is triggered because
consola
expects thedate
field to be an instance ofDate
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 callstoLocaleTimeString
on the date field, which only exists onDate
instances. 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 becauseconsola
expects aDate
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
The text was updated successfully, but these errors were encountered: