Repository navigation
fix(build): match main and polyfills scripts by file name - #203
Open
JasinRefiku wants to merge 1 commit into
Open
JasinRefiku wants to merge 1 commit into
JasinRefiku wants to merge 1 commit into
Conversation
updateScriptTags gave module-shim to the first script whose src contained "main" anywhere. With a base href such as /maintenance/, the dev server's /maintenance/@vite/client comes first and matches, so main.js stays a native module and cannot resolve shared packages from the importmap-shim: Failed to resolve module specifier "@angular/platform-browser" Match the file name (main.js, main-HASH.js, polyfills.js, polyfills-HASH.js) instead, for both lookaheads.
Contributor
Author
|
Note on the red I've left it out of this PR to keep the scope narrow. Happy to add a minimatch override here if you'd rather fix it in this PR. |
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
updateScriptTagsgivestype="module-shim"to the first<script>whosesrccontainsmainanywhere. When an app is served under a base href containing "main" (e.g./maintenance/), Vite injects its client script first:The Vite client gets
module-shimandmain.jsstaystype="module". Federation installs only animportmap-shim, so the nativeimport('./bootstrap')inmain.jsfails:The
polyfillslookahead has the same weakness.Fix
Both lookaheads now match the file name only:
main.js,main-HASH.js,polyfills.js,polyfills-HASH.js, with or without a leading path.Tests
Three new cases in
update-index-html.spec.ts:main(dev server shape), where onlymain.jsbecomesmodule-shimpolyfills, which is left untouched/app/main.jsand/app/polyfills.js, which are still matchedThe first two fail on
mainwithout the fix. All 12 specs in the file pass with it. I ran them with vitest 4.1 outside this repo's install, and did not runpnpm lint/pnpm typechecklocally.Context
Reported on the old repo as part of angular-architects/module-federation-plugin#933 (comment). This PR doesn't fully fix that issue's original case: a CDN
main.min.jsplaced before Angular'smain.jsstill matchesmain[.-].