-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Labels
feat: buildfeat: htmlp2-edge-caseBug, but has workaround or limited in scope (priority)Bug, but has workaround or limited in scope (priority)
Description
Describe the bug
Vite promotes import maps from the body of an HTML document to the head. However, it does so by using a regular expression to find import maps:
vite/packages/vite/src/node/plugins/html.ts
Lines 63 to 64 in d62dc33
const importMapRE = | |
/[ \t]*<script[^>]*type\s*=\s*(?:"importmap"|'importmap'|importmap)[^>]*>.*?<\/script>/is |
This causes unexpected issues, like when the import map is commented out; Vite still extracts it and puts it in the head, effectively uncommenting the user's code.
Check out these tips for parsing HTML with regex for a suggestion on making this more robust.
Steps to reproduce
Just add this to index.html
and observe the resulting <head>
tag or look for a console error about the import map being invalid JSON.
<!-- <script type="importmap">
this should be ignored
</script> -->
System Info
Binaries:
Node: 24.3.0
Yarn: 1.22.22
npm: 11.4.2
Browsers:
Chrome: 138.0.7204.92
Safari: 18.5
npmPackages:
vite: ^7.0.0 => 7.0.0
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
feat: buildfeat: htmlp2-edge-caseBug, but has workaround or limited in scope (priority)Bug, but has workaround or limited in scope (priority)