Keep the file extension in async bundle paths - #1990
Open
dasjideepak wants to merge 1 commit into
Open
dasjideepak wants to merge 1 commit into
dasjideepak wants to merge 1 commit into
Conversation
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
This branch has not been deployed
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.
Summary
Fixes #1959.
With lazy bundling, the async chunk URL loses the file extension. So
import()ofdist/index.cjsasks for/dist/index.bundle. The server then loadsdist/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.bundlepart, 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.bundlebecomesfoo.js.bundle). Old URLs still work on the server.Changelog: [Fix] Lazy bundle URLs keep the file extension, so
.cjs/.mjsasync imports load the right moduleTest plan
js-test.js: builds the chunk URL for a.cjsfile and reads it back. It fails onmainand passes with this change.js-test.jsand the URL list inserver-test.jsnow include the extension in chunk URLs.import('./dual.cjs')next to adual.js): before, "Requiring unknown module"; after, the right file loads.yarn jest packages/metro(2,325 passed), typecheck, eslint and prettier are clean.