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
When importing a JSON file using an alias, the app doesn't load and the following error shows in the browser console:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/json". Strict MIME type checking is enforced for module scripts per HTML spec.
In other words, if you have the @ alias declared in vite.config.js:
resolve: {alias: {"@": "./src",},},
And then import a JSON file using the alias:
importconfigfrom"@/config.json";
The error will happen.
This also happens when the aliased import is indirect. For example, if myFile.js imports config.json using a relative path but another file imports myFile.js using an alias.
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.
Describe the bug
When importing a JSON file using an alias, the app doesn't load and the following error shows in the browser console:
In other words, if you have the
@
alias declared invite.config.js
:And then import a JSON file using the alias:
The error will happen.
This also happens when the aliased import is indirect. For example, if
myFile.js
importsconfig.json
using a relative path but another file importsmyFile.js
using an alias.Reproduction
https://github.com/goodoldneon/vite-alias-json-bug-repro
Steps to reproduce
npm run dev
import config from "@/anotherFile.js"
insrc/App.jsx
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: