Skip to content

Keep the file extension in async bundle paths - #1990

Open
dasjideepak wants to merge 1 commit into
react:mainfrom
dasjideepak:fix/async-path-keep-extension
Open

dasjideepak wants to merge 1 commit into
react:mainfrom
dasjideepak:fix/async-path-keep-extension

Conversation

@dasjideepak

Copy link
Copy Markdown

Summary

Fixes #1959.

With lazy bundling, the async chunk URL loses the file extension. So import() of dist/index.cjs asks for /dist/index.bundle. The server then loads dist/index.js, which is a different file, and the app fails with "Requiring unknown module".

This change keeps the extension, for example /dist/index.cjs.bundle. The server already removes only the last .bundle part, so the chunk points to the right file. It also uses forward slashes, so Windows paths work in the URL.

Note: every async chunk URL now includes the extension (foo.bundle becomes foo.js.bundle). Old URLs still work on the server.

Changelog: [Fix] Lazy bundle URLs keep the file extension, so .cjs/.mjs async imports load the right module

Test plan

  • New test in js-test.js: builds the chunk URL for a .cjs file and reads it back. It fails on main and passes with this change.
  • Updated snapshots in js-test.js and the URL list in server-test.js now include the extension in chunk URLs.
  • Checked end to end with a small fixture (import('./dual.cjs') next to a dual.js): before, "Requiring unknown module"; after, the right file loads.
  • yarn jest packages/metro (2,325 passed), typecheck, eslint and prettier are clean.

The default async dependency path stripped the resolved file's extension,
so a lazy import of dist/index.cjs requested /dist/index.bundle. The server
then resolved index.js through sourceExts, a different module, and the app
failed with "Requiring unknown module". Keep the extension: the server
already strips only the .bundle suffix, so the chunk resolves to the exact
file. Also use posix separators so Windows paths don't produce backslashes.

Fixes react#1959
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 28, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Sep 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Async chunk URLs drop the file extension, so .cjs async imports fail with "Requiring unknown module"

1 participant