-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
json/svg/others? import does not work when dev server is behind a proxy #19181
Comments
The vite dev server serves the json files in two ways -- If you access to the file directly with the url like You can have a look at your devtool's network tab and see whether the query |
Can you elaborate on which kind exactly? As suggested by hyrious, the issue could be on reverse proxy functionality. |
Hello @adam-homeboost. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
@hyrious In both cases the |
@hi-ogawa It definitely seems to be related to the reverse proxy usage. I'm not sure if the exact nature matters very much but my current implementation is just a simple python server running under flask that is forwarding requests to the dev server using the The only difference that the dev server would see would be in the request headers. Here are examples of the two sets of headers for the two different situations:
Note that the 'Host' is the same on both. As for the other headers, I cannot imagine which differences matter. I can however control the headers the proxy sends, so willing to try whatever you suggest. So far however, replicating the headers that work to the case that does not isn't helping. |
Describe the bug
I have a react/typescript app running under the vite dev server. This dev server is running behind a reverse proxy.
When doing
import data from "./data.json"
I get error: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.
Observationally from the network console, I can see that
data.json
is being loaded by the browser, but it is raw json, not the transformed to javascript code that this import should usually generate.I can see this also happen with the svg logo in the basic "getting started" recipe.
The main thing that appears to be driving this is that I am running the dev server behind a reverse proxy. If I hit the dev server directly via one of the urls it is listening on, then the import works! It is only when the dev server is hit via the reverse proxy that this fails. To the best of my knowledge, the only difference there from the dev server's perspective is going to be some HTTP request headers (such as Host, etc).
Reproduction
needs a proxy, can't be done with just a repo.
Steps to reproduce
A simple way to go:
data.json
file in srcimport data from "./data.json"
in src/App.tsx`vite
dev serverbase
depending on your setup). Open console, observe import errorsSystem Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: