During our regular workerd version bump in workers-sdk, some of our unit/fixture tests started failing with
TypeError: Cannot read properties of undefined (reading 'bind')
❯ node-internal:internal_timers:107:53
After some investigation, we realised that changing the compatibility date of the Workers under test to 2024-09-23 (from 2024-01-01) fixes the issue. After further investigation (thank you @vicb ♥ ), we found that the root cause is that the new implementation of node:timers relies on globalThis.setImmediate[1] which is only available with nodejs_compat_v2[2]
This means that the current implementation of node:timers might break users having a compat date before 2024-09-23.
[1]
|
export const setImmediate = globalThis.setImmediate.bind(globalThis); |
|
|
|
export const clearImmediate = globalThis.clearImmediate.bind(globalThis); |
[2]
|
// An approximation of Node.js setImmediate `Immediate` object. |
|
// This is used only when the `nodejs_compat_v2` compatibility flag is enabled. |
During our regular
workerdversion bump inworkers-sdk, some of our unit/fixture tests started failing withAfter some investigation, we realised that changing the compatibility date of the Workers under test to
2024-09-23(from2024-01-01) fixes the issue. After further investigation (thank you @vicb ♥ ), we found that the root cause is that the new implementation of node:timers relies on globalThis.setImmediate[1] which is only available with nodejs_compat_v2[2]This means that the current implementation of node:timers might break users having a compat date before 2024-09-23.
[1]
workerd/src/node/internal/internal_timers.ts
Lines 137 to 139 in b982f8b
[2]
workerd/src/workerd/api/global-scope.h
Lines 387 to 388 in b982f8b