Skip to content

node:timers breaks for Workers without the nodejs_compat_v2 compatibility flag #3377

@CarmenPopoviciu

Description

@CarmenPopoviciu

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions