-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
fix(optimizer): externalize virtual modules for html like files #21001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+54
−1
Conversation
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
…p-scan Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix shouldExternalizeDep call in scan.ts
fix(deps): call Oct 24, 2025
shouldExternalizeDep for virtual modules with html-like extensions in dep scanner
Copilot finished work on behalf of
sapphi-red
October 24, 2025 15:04
sapphi-red
requested changes
Oct 25, 2025
Member
sapphi-red
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot please fix the test failure
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Contributor
Author
Copilot finished work on behalf of
sapphi-red
October 25, 2025 00:50
commit: |
sapphi-red
approved these changes
Oct 26, 2025
shouldExternalizeDep for virtual modules with html-like extensions in dep scannershouldExternalizeDep for virtual modules with html-like extensions in dep scanner
shouldExternalizeDep for virtual modules with html-like extensions in dep scanner
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
feat: deps optimizer
Esbuild Dependencies Optimization
p2-edge-case
Bug, but has workaround or limited in scope (priority)
trigger: preview
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.
Fix issue #14151: Call
shouldExternalizeDepfor virtual modules in dep-scanfixes #14151
close #14206
shouldExternalizeDepafterbuild.onResolve({ filter: htmlTypesRE }Problem
When importing a virtual module with an HTML-like file extension (
.vue,.svelte,.html,.astro,.imba), the dependency scanner would throw anENOENT: no such file or directoryerror during the first dev server start. This happened because the scanner attempted to read virtual modules from the filesystem.Solution
Added a check using
shouldExternalizeDep()in thehtmlTypesREonResolve handler (line 505 in scan.ts). This function checks if a module is virtual (by detecting the null byte prefix\0or if the resolved ID equals the raw ID) and returns early to externalize it, preventing the scanner from trying to load it from disk.Changes Made
Core Fix (4 lines):
packages/vite/src/node/optimizer/scan.tsto callshouldExternalizeDep()before trying to load HTML-like filesTest Case:
playground/optimize-deps/vite.config.jsprovidingvirtual:test-virtual-file/Foo.vueplayground/optimize-deps/index.htmlwith inline script to test virtual module importplayground/optimize-deps/__tests__/optimize-deps.spec.tsto verify no scan errors occurVerification:
.vueextension load correctlyOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.