You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dynamic import with type: 'json' causes syntax error on Firefox #19095
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.
@JamesParrott Your issue is likely different and that's babel / react plugin issue vitejs/vite-plugin-react#385 It should be fixed (workarounded) in latest react plugin, so please try it after upgrading it.
changed the title [-]Dynamic import with `type: 'json'` causes syntax error[/-][+]Dynamic import with `type: 'json'` causes syntax error on Firefox[/+]on Dec 31, 2024
Failed to load module script: Expected a JSON module script but the server responded with a MIME type of "text/javascript". Strict MIME type checking is enforced for module scripts per HTML spec.
Reacted by Hyunbin Seo, idler and Sergej Sintschilin
I'd like to investigate this on current main and prepare a focused fix with regression coverage for dynamic JSON imports. I'll check the earlier attempts and verify the behavior in the browser before opening a PR.
Activity
JamesParrott commentedon Dec 30, 2024
hi-ogawa commentedon Dec 31, 2024
@JamesParrott Your issue is likely different and that's babel / react plugin issue vitejs/vite-plugin-react#385 It should be fixed (workarounded) in latest react plugin, so please try it after upgrading it.
[-]Dynamic import with `type: 'json'` causes syntax error[/-][+]Dynamic import with `type: 'json'` causes syntax error on Firefox[/+]hi-ogawa commentedon Dec 31, 2024
Vite doesn't strip off import attributes for dynamic import, so the browsers get errors depending on their support.
vite/packages/vite/src/node/plugins/importAnalysis.ts
Lines 500 to 503 in e1b520c
On Firefox, it's a syntax error as it looks like they don't accept it yet https://bugzilla.mozilla.org/show_bug.cgi?id=1736059
On Chrome, the syntax is fine, but Vite is responding
text/javascript, so this causes a different error:https://stackblitz.com/edit/vitejs-vite-8nxtabzl?file=src%2Fmain.js
JamesParrott commentedon Jan 1, 2025
Excellent. Thankyou very much :)
fix: strip import attributes from dynamic imports in dev mode
fix(genshin-world): the parity page strips a dynamic JSON import's ty…
fix(genshin-world): the parity page strips a dynamic JSON import's ty…
fix(genshin-world): the parity page strips a dynamic JSON import's ty…
fix(genshin-world): the parity page strips a dynamic JSON import's ty…
fix(genshin-world): the parity page strips a dynamic JSON import's ty…
chore(deps): vize 0.691.0 and vite 8.3.6
Johnx-w commentedon Nov 11, 2026
I'd like to investigate this on current main and prepare a focused fix with regression coverage for dynamic JSON imports. I'll check the earlier attempts and verify the behavior in the browser before opening a PR.