Skip to content

[BUG]: Compatibility issue with Cloudflare Workers #1139

Open
0 of 2 issues completed
Open
Bug
0 of 2 issues completed
@liblaf

Description

@liblaf

What happened?

I attempted to use @octokit/webhooks in a Cloudflare Worker. When processing GitHub webhook events, the worker throws a TypeError: setTimeout(...).unref is not a function. This occurs because, quoting from Cloudflare Workers Timers Docs:

When called from a global level (on globalThis), functions such as clearTimeout and setTimeout will respect web standards rather than Node.js-specific functionality. For complete Node.js compatibility, you must call functions from the node:timers module.

timeout = setTimeout(() => {
didTimeout = true;
resolve(
new Response("still processing\n", {
status: 202,
headers: { "Content-Type": "text/plain" },
}),
);
}, 9000).unref();

Expected Behavior: The library should work in Cloudflare Workers without errors. Since unref() is not available in browser-like environments or CF Workers, the code should check for its existence before calling it or avoid using unref() in web-targeted builds.

Versions

# wrangler.toml
compatibility_date = "2025-04-27"
compatibility_flags = ["nodejs_compat"]

Relevant log output

2025-04-27 12:51:29.308 ERROR   /home/liblaf/github/liblaf/liblaf-bot/.wrangler/tmp/dev-pYYrLd/index.js:170
 TypeError  setTimeout(...).unref is not a function
error stack:
  • index.js
        /home/liblaf/github/liblaf/liblaf-bot/.wrangler/tmp/dev-pYYrLd/index.js:148
  • 

  • index.js
        /home/liblaf/github/liblaf/liblaf-bot/.wrangler/tmp/dev-pYYrLd/index.js:147
  • index.js
        /home/liblaf/github/liblaf/liblaf-bot/.wrangler/tmp/dev-pYYrLd/index.js:170
  • index.js
        /home/liblaf/github/liblaf/liblaf-bot/.wrangler/tmp/dev-pYYrLd/index.js:1
  • index.js
        /home/liblaf/github/liblaf/liblaf-bot/.wrangler/tmp/dev-pYYrLd/index.js:1
  • index.js
        /home/liblaf/github/liblaf/liblaf-bot/.wrangler/tmp/dev-pYYrLd/index.js:170
  • index.js
        /home/liblaf/github/liblaf/liblaf-bot/.wrangler/tmp/dev-pYYrLd/index.js:170
  • index.js
        /home/liblaf/github/liblaf/liblaf-bot/.wrangler/tmp/dev-pYYrLd/index.js:170
  • index.js
        /home/liblaf/github/liblaf/liblaf-bot/.wrangler/tmp/dev-pYYrLd/index.js:170

Code of Conduct

  • I agree to follow this project's Code of Conduct

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working as documented, or is being fixed

    Type

    Projects

    Status

    🔥 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions