Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type

when i run my vite project i get error on the console . Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

there is no other error

like image 835
מייל אירועים Avatar asked Sep 13 '25 16:09

מייל אירועים


2 Answers

Changing

vite build --base=./

to

vite build --base=/

solve my problem.

like image 192
Mahesh Shitole Avatar answered Sep 15 '25 07:09

Mahesh Shitole


I had the same error and managed to fix it.

By default Vite builds html with absolute asset references into the dist directory, because it assumes you deploy the dist folder to a root domain.

But if your project lives in a subdirectory like mine does, the absolute asset references won't work correctly.

Vite has a base config option that you can tweak to have it build relative assets urls. Check the docs.

// vite.config.js
export default {
  base: './',
};

Or you can pass this config option when running the build command through the command line:

vite build --base=./

This works for Vite 4.3.9.

like image 43
bramchi Avatar answered Sep 15 '25 07:09

bramchi