Repository navigation
fix(vite): classify minified ESM deps chunks as ESM - #11622
Merged
Merged
Conversation
The deps-bundle module classifier anchored import/export syntax to line
starts, so a minified .js chunk with export{...} after statements on one
line was treated as opaque CJS and the served shim dropped every named
export, breaking startup before the app mounts. The star re-export
scanners carried the same line-start assumption.
Run classification and the export scanners on a literal-masked copy:
maskJsComments gains a mode that also blanks string/template/regex
interiors (positions preserved) and now honors template ${} nesting —
its desync previously masked real code after nested literals. Keyword
matches are guarded by an identifier/member lookbehind so $export and
obj.import/obj.export cannot flip CJS to ESM, and mid-line
export * from / export * as re-exports are followed with the specifier
read back from the original text.
|
View your CI Pipeline Execution ↗ for commit 1e6c16c
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
farfromrefug
reviewed
Nov 9, 2026
| } | ||
|
|
||
| const ESM_SYNTAX_RE = /^[ \t]*(?:import[\s{"'*]|export[\s{*])/m; | ||
| // ESM markers can sit anywhere on a line — minified chunks emit |
Collaborator
There was a problem hiding this comment.
those AI comments are far too long. I think it is best to limit any comment to 2/3 lines or the code will become a book to read with a few lines of code ;)
it applies to all comments
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.
Fixes #11621
What
collectDepsModuleExportInfoinhmr/server/deps-bundle.tsclassified modules withESM_SYNTAX_RE = /^[ \t]*(?:import…|export…)/m— anchored to line starts. A minified.jschunk (const value=1;export{value as g};) fell through tocollectCjsExportInfo, gotopaqueCjs: true, and the served/ns/mshim emitted onlyexport default, dropping every named export and failing startup in the host ESM linker before the app mounts.How
maskJsComments(code, literals)gains a mode that also blanks string/template/regex literal interiors (delimiters and character positions preserved). Its template skip now honors${}interpolation — a nested literal previously desynced backtick pairing and masked real code after it.export * as/export {…}/export * fromscanners run on the masked copy, so mid-line ESM is found without matching look-alike text inside literals or comments.starRewas line-anchored andstarAsRerequired spaces around*— both shared the defect.(?<![.$\u200c\u200d\p{ID_Continue}]), so$exportidentifiers andobj.import/obj.exportmember access cannot flip a CJS file to ESM.export * from, thefromposition is located on the masked copy and the specifier literal is read back from the original text at the same offset.Test plan
@nativescript/vite8.0.20: minified.js,.mjs,export{mt as g,xx as h}after declarations, mid-lineexport*from,export*as ns, mid-lineexport default— all produce correct names and shims.export/importtext inside strings, templates, line/block comments, and regexes;$exportidentifiers;obj.import/obj.exportmembers — all stay CJS.node_modulesfiles old-vs-new: the only differences were names harvested from embedded code strings (now correctly excluded) and real mid-line ESM now detected.export * fromtargets still returnnames: null(per-module serving fallback), and opaque-CJS (module.exports = ...) still returnsopaqueCjs.