When serving a new Vite + React project like so
- Create new React + Vite project via
npm create vite
- Select React => TypeScript
- Install dependencies via
npm install
- Build via
npm run build
- CD into
dist
dir - Run app locally via
npx http-serve
- Open url in browser
everything works as expected.
But when I delete the public
directory and simplify the main.tsx file to
import React from 'react'
import ReactDOM from 'react-dom/client'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<div>Foo</div>
</React.StrictMode>,
)
the application build looks fine but when serving it I get a blank page with the error message
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “application/octet-stream”. Strict MIME type checking is enforced for module scripts per HTML spec.
Does someone know what’s wrong or missing?