Skip to content

Reproduce dynamic import failure from redirected fallback module - #6963

Draft
edmundhung wants to merge 1 commit into
mainfrom
edmundhung/module-fallback-redirect-repro
Draft

Reproduce dynamic import failure from redirected fallback module#6963
edmundhung wants to merge 1 commit into
mainfrom
edmundhung/module-fallback-redirect-repro

Conversation

@edmundhung

@edmundhung edmundhung commented Aug 10, 2026

Copy link
Copy Markdown
Member

This adds a standalone reproduction for a V2 module fallback issue involving redirects and dynamic imports. It intentionally contains no runtime fix and does not depend on Vite or Workers SDK.

The Worker imports two bare dependencies that the fallback service redirects to canonical file:///project/node_modules/... URLs:

  • static-test-dependency statically imports ./value.mjs and succeeds.
  • dynamic-test-dependency calls import("./value.mjs") from load() and fails.

With workerd@1.20260810.1, the request logs static import: loaded, then returns HTTP 500 with:

Referring module not found in the registry: file:///project/node_modules/dynamic-test-dependency/index.mjs

The fallback service never receives a request for the dynamic dependency's child module. This appears to happen because the dynamic import uses the redirected canonical URL as its referrer, while that canonical URL is not present in the isolate's module registry. Static imports from the same kind of redirected module use the original pre-redirect alias as their referrer and succeed.

The related Workers Vitest integration currently needs an isolated import-rewriting workaround for this behavior: cloudflare/workers-sdk#15117

To reproduce:

  1. Run node samples/module-fallback-redirect/fallback.mjs.
  2. Run npx workerd@1.20260810.1 serve samples/module-fallback-redirect/config.capnp --experimental.
  3. Run curl http://127.0.0.1:8080.

@ask-bonk

ask-bonk Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Good - I've confirmed the fallback service correctly handles both the static import path (where ./value.mjs resolves against the original file:///bundle/static-test-dependency to file:///bundle/value.mjs, which then gets redirected) and the dynamic import path (where ./value.mjs would resolve against the post-redirect file:///project/node_modules/dynamic-test-dependency/index.mjs to file:///project/node_modules/dynamic-test-dependency/value.mjs, which the fallback service handles directly - but this path is never reached because the referrer lookup fails first).

The reproduction is well-constructed and correctly demonstrates the bug. Let me think about whether there are any actionable issues:

  1. Code correctness: The reproduction sample code is correct and well-structured. It properly uses the V2 fallback protocol (POST with JSON body), correctly handles redirects, and demonstrates both the working (static) and broken (dynamic) paths.

  2. Scope concern: This PR adds only a samples/ reproduction with no fix, no test integrated into the build system. The samples/ directory already contains similar standalone examples (like module_fallback/) that aren't part of the Bazel build, so this is consistent.

  3. No backward compat, security, or API concerns: This is purely a new sample directory with no runtime changes.

  4. The file:///bundle/value.mjs case in the fallback: The static import path goes through file:///bundle/value.mjs because the referrer for static imports is the original pre-redirect specifier file:///bundle/static-test-dependency. But static-test-dependency is not a path with a file extension, so ./value.mjs resolves to file:///bundle/value.mjs. The fallback then redirects this to the correct canonical path. This is accurate behavior and the fallback service handles it correctly.

  5. Missing case for file:///project/node_modules/dynamic-test-dependency/value.mjs: The fallback service does handle this case (line 65-68), but it will never be reached in practice because the dynamic import fails before even reaching the fallback. This is fine - it documents what the correct behavior would be if the bug were fixed.

I don't see any actionable issues in this PR. The reproduction is clean, minimal, well-documented, and correctly demonstrates the bug described.

LGTM

github run

@codspeed-hq

codspeed-hq Bot commented Aug 10, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 10.22%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 71 untouched benchmarks
⏩ 129 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
bm_Promise_Fib10 20.1 µs 18.3 µs +10.22%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing edmundhung/module-fallback-redirect-repro (d568e22) with main (d900d79)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@jasnell

jasnell commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Fix here: #6965

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

Successfully merging this pull request may close these issues.

2 participants