fix: lazy-load cloudflare:workers to support non-Worker runtimes - #193
Draft
LordCoughmann wants to merge 2 commits into
Draft
fix: lazy-load cloudflare:workers to support non-Worker runtimes#193LordCoughmann wants to merge 2 commits into
LordCoughmann wants to merge 2 commits into
Conversation
The top-level import of cloudflare:workers causes the module to crash in non-Worker runtimes (Node.js, Deno, Bun, browsers). Replace with a lazy getter using createRequire for ESM compliance. The module is only resolved when Browser Binding functions are actually called. Call-site errors (No binding found for X) remain unchanged.
LordCoughmann
force-pushed
the
fix/lazy-cloudflare-workers-import
branch
from
June 5, 2026 07:38
014a5be to
d6b22d7
Compare
18 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
I ran into this when loading
@cloudflare/playwrightfrom Node.js, Deno, and Bun: the top-levelcloudflare:workersimport crashes beforeconnectOverCDP()can be used with an external CDP endpoint.Reproduction: https://github.com/LordCoughmann/repo-cf-playwright-lazy-import
pnpm install node index.mjs # → Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supportedSolution
I worked around this in my own fork by resolving
cloudflare:workerslazily only when Browser Binding functions are called. This keeps Worker behavior unchanged while allowing the package to load in non-Worker runtimes; invalid Browser Binding calls still report the existingNo binding found for ...error.Validation
npm run test:node-importpasses from the non-Worker package directory.chromium.connectOverCDPis available outside Workers.Refs: #88, #59