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

fix: consola crashes due to 'logObj.date.getTime is not a function' #700

Open
eerive opened this issue Jul 25, 2024 · 3 comments
Open

fix: consola crashes due to 'logObj.date.getTime is not a function' #700

eerive opened this issue Jul 25, 2024 · 3 comments
Labels
bug Something isn't working needs reproduction

Comments

@eerive
Copy link

eerive commented Jul 25, 2024

🐛 The bug

The Nuxt 3 application that I'm currently developing using Typescript has devtools enaled and always throws an error during the initialization which stops the whole page from loading correctly.

index.mjs:48  [nuxt] error caught during app initialization TypeError: logObj.date.getTime is not a function
    at Consola._logFn (core.mjs:353:70)
    at Consola.log (core.mjs:306:19)
    at dev-server-logs.js:28:8
    at index.mjs:48:66
    at index.mjs:48:56
    at async dev-server-logs.js:35:4
    at async setup (client.mjs:38:36)
    at async applyPlugin (nuxt.js:137:25)
    at async executePlugin (nuxt.js:173:9)
    at async applyPlugins (nuxt.js:187:5)

It seems that Consola is trying to use the method getTime even though logObj.date is a String?
It happens when

"[Vue warn]: Property undefined was accessed during render but is not defined on instance.
 " at Proxy.<anonymous> (eval-4efcead9.cdp)""

is called, and for some reason logObj.date is overwritten by the Object.assign function to a string instead of a Date object.

Screenshot 2024-07-25 at 12 40 55

Could this be a bug of the Consola dependency or is this due to dev-server-logs.js sending a wrongly typed object?

🛠️ To reproduce

  • Set devtools enabled

🌈 Expected behavior

Page not completely halting when this error occurs

@eerive eerive added the bug Something isn't working label Jul 25, 2024
@ElPrudi
Copy link

ElPrudi commented Mar 19, 2025

Same problem here. Started happening to me when I added a custom json payload to get custom classes to work:

export default definePayloadPlugin(() => {
  definePayloadReducer('JSONfiable', data => data && typeof data === 'object' && 'toJSON' in data && JSON.stringify(data.toJSON()))
  definePayloadReviver('JSONfiable', data => JSON.parse(data))
})

Found in this issue

Edit: I've replaced JSON.parse with superjson.parse from the package superjson. This fixed my problem.

@pi0
Copy link
Member

pi0 commented Mar 19, 2025

Feel free to open an issue in consola with some sort of reproduction. I think issue is that user payload object wrongly detected.

@GoodWave2020
Copy link

I have created an issue as below.
unjs/consola#351

It looks like it's currently being worked on.
unjs/consola#372

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs reproduction
Projects
None yet
Development

No branches or pull requests

5 participants