harttle/liquidjs

`performance` still breaks in Node 15

vrugtehagel opened this issue ยท 5 comments

A followup on #728.

The PR I opened today (#729) did resolve this issue for Node 14, but unfortunately, Node 15 still throws an error due to the node: prefix in the import.

Not sure what to do with this, actually, since the test runner doesn't even want to run on Node 15. What do you suggest, @harttle? Happy to open a followup PR with any suggestions you might have.

From the Jest docs:

The supported Node versions are 14.15, 16.10, 18.0 and above.

We're experiencing a similar problem not in Node but using LiquidJS as a WASM module compiled with Javy which doesn't seem to have access to monotonic timers out of the box.

The only easy fix I found was to define a globalThis.performance object with a now method that always returns 0 since we're already limiting the run time externally.

I guess, one solution is to use something like

const startupTime = globalThis.performance ? 0 : (globalThis.Date?.now() ?? 0);
const now = () => {
  if(globalThis.performance){
    return globalThis.performance.now();
  }
  const current = globalThis.Date?.now() ?? 0;
  return current - startupTime;
}

and then we can drop the node:perf_hooks imports altogether. I know Date.now() is not as accurate, but better than nothing anyway. And this also fails gracefully if you are using an environment that has no timers at all.

@vrugtehagel agreed. We can fallback to Date.now() for platforms don't provide the performance global variable. Let me work on a fix.

the test runner doesn't even want to run on Node 15

I can run jest locally with Node@15, I'll try include it on CI.

๐ŸŽ‰ This issue has been resolved in version 10.16.3 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€