-
Notifications
You must be signed in to change notification settings - Fork 494
Open
Labels
feature requestRequest for Workers team to add a featureRequest for Workers team to add a featurenodejs compat
Description
As discussed when the Node timers were implemented in January 25 (on this PR), the global timer functions (setTimeout, setInterval) do not implement the Node API but the Web Platform API:
// This code works fine in Node but crashes in workerd
const timeout = /*globalThis.*/setTimeout(...);
timeout.refresh(); // crashes, timeout is a number
// However this works fine in both Node and Workerd
import nodeTimers from `node:timers`;
const timeout = nodeTimers.setTimeout(...);
timeout.refresh();This has been discussed with @jasnell and @danlapid
One of the problem here is that the timers module calls in the global functions which make it quite complex to polyfill the functions without creating an infinite loop.
One workaround is to inject the following code at the top of the generated JS bundle:
import {setInterval, clearInterval, setTimeout, clearTimeout, setImmediate, clearImmediate} from "node:timers";But this has downside, see i.e. opennextjs/opennextjs-cloudflare#1036
Could we please implement Noce compatible global timer functions behind a compatibility flag?
Metadata
Metadata
Assignees
Labels
feature requestRequest for Workers team to add a featureRequest for Workers team to add a featurenodejs compat