Server library is trying to load the js file as "text/html" on the cloud

445 Views Asked by At

I have a react typescript vite application and the build and run commands are as follows:

"build": "tsc && vite build",
"start:prod": "serve -s ./dist -p 8080"

It works just fine locally, without any problems, but in the cloud (using openshift) it gives me an error message:

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.

I have an additional route for this microservice in openshift but I have to set the base in the vite.config.ts to be './' then it successfully get the files from the server but with an improper content-type.

I have also set the resolve extensions in the vite.config.ts but it didn't help.

Any ideas what could have caused this error?

1

There are 1 best solutions below

1
User.Anonymous On

You need to configure your backend API with a Content-Type header as text/javascript on this file (or all

You can see it with Chrome debug, panel Network to look how the ressource is requested.