denoland / deploy_feedback

For reporting issues with Deno Deploy
https://deno.com/deploy
74 stars 5 forks source link

performance.timeOrigin = undefined on Deno Deploy #696

Open Kukusik8 opened 1 month ago

Kukusik8 commented 1 month ago

When i deploy my code on Deno Deploy, I have this error in the logs and it says "ERROR: RangeError: Invalid time value at Date.toISOString ()". It happens because of this line in my code

const start = performance.timeOrigin; //undefined

I've tried to use Date.now() instead of performance.timeOrigin, and it worked. *Btw performance.now() working as well.

Does someone know what is the possible solution? Deno on latest version.

It deployes successfully, but on Deno logs this error.

It happens here:

const start = performance.timeOrigin; //undefined
const now = performance.now();

const iso = new Date(start + now).toISOString(); //error
Kukusik8 commented 1 month ago
const Timestamp = function (precision = 6) {
  if (!type.int(precision)) precision = 6;
    const p = precision;
    const start = performance.timeOrigin; //undefined
    const now = performance.now();
    const iso = new Date(start + now).toISOString();

    const microseconds = (((start + now) % 1000) / 1000).toFixed(p).slice(2);

      return iso.substring(0, iso.indexOf('.') + 1) + microseconds + 'Z';
};
export default Timestamp;

Here my code. I use deployctl, don't use npm.

jsejcksn commented 1 month ago

Related:

esroyo commented 2 days ago

As a workaround you may define an approximate timeOrigin (once) at the start of your entrypoint:

if (!performance.timeOrigin) {
    Object.defineProperty(performance, 'timeOrigin', { value: Date.now() - performance.now() });
}