After deploying your React App built with Vite, you may see the console error message says, Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". ...
.
This is because you may set the wrong base while you set the vite.config.js/ts
file.
I faced this issue when I set the path alias
from the vite.config.ts
file. I set the base
with ./
, but it gives an error when loading files from the html
. the base
path should be /
, not ./
.
So If you have any issues with the error message above please check your vite.config.ts
file.
You can also set the base path from the script in the package.json
. Please ensure your base path is set correctly in your script as well.
The way to set the base path from the script is as follows.
vite build --base=/
.
Top comments (2)
Thanksssssssssss
Excellent