Skip to content

Octokit on Cloudflare Workers while importing bindings globally throws an error #794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ariesclark opened this issue May 13, 2025 · 1 comment

Comments

@ariesclark
Copy link

ariesclark commented May 13, 2025

using Octokit on Cloudflare Workers while importing bindings globally errors.

import { env } from "cloudflare:workers";
import { Octokit } from "octokit";

// throws
export const github = new Octokit({
	auth: env.GITHUB_TOKEN,
});

with the following error:

Uncaught Error: Disallowed operation called within global scope. Asynchronous I/O (ex: fetch() or connect()), setting a timeout, and generating random values are not allowed within global scope. To fix this error, perform this operation within a handler. https://developers.cloudflare.com/workers/runtime-apis/handlers/
    at null.<anonymous> (index.js:972:51) in _startAutoCleanup
    at null.<anonymous> (index.js:899:18) in Group
    at null.<anonymous> (index.js:6834:19) in createGroups
    at null.<anonymous> (index.js:6880:5) in throttling
    at null.<anonymous> (index.js:4126:54) in Octokit
    at null.<anonymous> (index.js:4024:9) in OctokitWithDefaults
    at null.<anonymous> (index.js:9866:14)

Workaround

import { env } from "cloudflare:workers";
import { Octokit } from "octokit";

// exclude the "throttling" plugin.
// see https://github.com/octokit/plugin-throttling.js/issues/794
Octokit.plugins = Octokit.plugins.filter((plugin) => plugin.name !== "throttling");

export const github = new Octokit({
	auth: env.GITHUB_TOKEN,
});
@wolfy1339
Copy link
Member

From what I've gathered from the very sub-optimal minimal stack trace information, it's not an issue with Octokit directly but one with the Bottleneck dependency which is unmaintained

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants