Skip to content
Advertisement

Failed to load module script: Expected a JavaScript module

The error which I was facing

I am using vite as build tool for my react app and golang as backend.

I built the app for production and host the app on my http server.

my directory structure:

JavaScript

To host my files the code looks like (inside main.go)

JavaScript

in index.html

JavaScript

The code did actually send correct files but with wrong headers.

my network panel in dev tools

Advertisement

Answer

So I had to write my own file server to set the headers manually like:

JavaScript

(please optimize if the code is bad, I made the solution myself and I tried so many stuff to fit my needs)

Now with that I recevied the correct files with correct headers.

And I couldn’t find any solutions to work with custom headers using http.FileServer in http package. And please provide a easy solution if it exists.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement