-
Notifications
You must be signed in to change notification settings - Fork 82
Description
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
clearTimeoutandsetTimeoutwill respect web standards rather than Node.js-specific functionality. For complete Node.js compatibility, you must call functions from thenode:timersmodule.
webhooks.js/src/middleware/web/middleware.ts
Lines 83 to 91 in 6dd5d30
| 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
@octokit/[email protected]
[email protected]
# 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:170Code of Conduct
- I agree to follow this project's Code of Conduct
Sub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
Status