fix: Allow internal module resolution to access builtin modules#6105
Closed
fix: Allow internal module resolution to access builtin modules#6105
Conversation
When resolving modules with INTERNAL_ONLY option (used by extension modules and internal builtins), also allow BUILTIN modules to be resolved as a fallback. This enables extension modules (like miniflare's dispatch-namespace worker) to import public built-in modules like cloudflare:workers. Previously, extension modules could only import INTERNAL modules (like cloudflare-internal:workers), which have a different export structure than the public BUILTIN modules. This forced workarounds in libraries like capnweb that needed to handle both module types. The resolution order is preserved: 1. First try to find an INTERNAL module (preferred) 2. If not found, try to find a BUILTIN module (fallback) 3. Only if neither is found, return none
penalosa
added a commit
to cloudflare/workers-sdk
that referenced
this pull request
Feb 18, 2026
Extension workers can now import cloudflare:workers directly instead of needing it rewritten to cloudflare-internal:workers. This simplifies the build by removing: - extensionWorkerPaths list - rewriteCloudflareWorkersToInternalPlugin Note: This change depends on cloudflare/workerd#6105 which allows INTERNAL_ONLY module resolution to also access BUILTIN modules.
mikea
approved these changes
Feb 18, 2026
anonrig
approved these changes
Feb 18, 2026
jasnell
requested changes
Feb 18, 2026
Collaborator
There was a problem hiding this comment.
A key difference between BUILTIN and INTERNAL_ONLY is that BUILTIN modules can be overriden by the worker bundle...
const helloWorld :Workerd.Worker = (
modules = [
(name = "worker", esModule = embed "worker.js"),
(name = "cloudflare:workers", esModule = "export default 1;")
],
compatibilityDate = "2023-02-28",
);
import * as foo from 'cloudflare:workers';
console.log(foo); // [Module: null prototype] { default: 1 }
We need to evaluate whether this change is correct. The INTERNAL_ONLY behavior here is quite intentional.
penalosa
added a commit
to cloudflare/workers-sdk
that referenced
this pull request
Feb 18, 2026
Extension workers can now import cloudflare:workers directly instead of needing it rewritten to cloudflare-internal:workers. This simplifies the build by removing: - extensionWorkerPaths list - rewriteCloudflareWorkersToInternalPlugin Note: This change depends on cloudflare/workerd#6105 which allows INTERNAL_ONLY module resolution to also access BUILTIN modules.
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.
When resolving modules with
INTERNAL_ONLYoption, also allow BUILTIN modules to be resolved as a fallback.This enables extension modules (like miniflare's
dispatch-namespace.worker.ts, which sparked this PR) to import public built-in modules likecloudflare:workers.Alternative to cloudflare/capnweb#139