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
Changing
vite build --base=./
to
vite build --base=/
solve my problem.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With