Dynamically inserted importmap doesn't work in development mode #15192
Labels
feat: html
has workaround
p3-minor-bug
An edge case that only affects very specific usage (priority)
Describe the bug
Inserting an importmap at runtime via a
script
statement inhead
does not work in development mode because the script that is inserting it is placed after the module import of@vite/client
. This results in the following error:This issue only affects the development mode because it it caused by the presence of the
@vite/client
import.Related issues:
Workaround: trick Vite into thinking that the script that is inserting the importmap is an importmap itself - this will make sure that it gets sorted before the module import of
@vite/client
. This can be achieved by adding an attribute to it that matches this regular expression (e.g.data-vite-workaround="type=importmap"
).Reproduction
https://stackblitz.com/edit/vitejs-vite-yde4az?file=index.html
Steps to reproduce
Run
npm install && npm run dev
.Expected result:
Actual result:
Note that running
npm install && npm run build && npm run preview
works as expected.System Info
The text was updated successfully, but these errors were encountered: