Open
Description
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,
});
Metadata
Metadata
Assignees
Labels
No labels