blog

"Expected a JavaScript Module Script" Error: How to Fix It

Blank page and "Failed to load module script" after deploying your Bolt or Vite app to Netlify? You deployed source code, not the build. Here's the fix.

6 min readNetlifyBoltFixesBlank screen

Your app works perfectly in Bolt's preview. You put it on Netlify, open the live address and see a blank white page. The browser console has one red line, something like:

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.

The error looks technical, but its meaning is simple: the browser received your app's source code instead of the finished, built app. This guide explains why that happens and gives three ways to fix it.

What you see

  • The live site is blank or almost blank.
  • Open the browser console (right-click → Inspect → Console, or F12) and reload. You'll see Failed to load module script with the text above. The file named at the start of the line is usually main.tsx or main.jsx.
  • The MIME type in the message may differ — application/octet-stream, text/plain or text/html — but the problem is the same.

A real example: in this Netlify forum thread, a site built with Bolt worked in the Bolt preview, but the live site was blank with exactly this error pointing at main.tsx.

Why it happens

Browsers are strict about scripts loaded as modules. MDN's guide to MIME types says JavaScript should always be served with the type text/javascript, and that you shouldn't assume a script served with any other type will load or run. For module scripts, browsers enforce this — hence "strict MIME type checking is enforced for module scripts".

So why is the server sending the wrong type? Because the file it sends isn't JavaScript at all.

Apps from Bolt, Lovable and most Vite projects are written in TypeScript and JSX (.tsx files). Browsers can't run those directly. Two things turn them into real JavaScript:

  • In the preview, a development server converts files on the fly as the browser asks for them. Vite's guide explains that index.html is the entry point and Vite resolves the <script type="module" src="..."> that references your source code.
  • For a live site, vite build does the conversion once. Vite's build guide says it uses index.html as the entry and produces a bundle "suitable to be served over a static hosting service". The output goes into the dist folder by default.

If you upload the project folder itself, the live site serves the original index.html, which still points to /src/main.tsx. The browser downloads a .tsx file, the host labels it as a generic file type, and the browser refuses to run it. Nothing renders.

In the forum thread, a Netlify community member spotted exactly this: the user had downloaded the project from Bolt, extracted it and uploaded the project folder — "deploying source code, not build output".

Fix 1: Build first, then upload the dist folder

This is the quickest fix if you deploy by hand.

  1. Download your project from Bolt (or open it on your computer if it's already there) and unzip it.
  2. Make sure you have Node.js installed.
  3. Open a terminal in the project folder (the folder with package.json).
  4. Install the dependencies:
npm install
  1. Build the app:
npm run build
  1. When it finishes, a new folder called dist appears. Inside are index.html and an assets folder with .js and .css files. That's your finished site.
  2. Deploy the dist folder, not the project folder:
    • In the Netlify dashboard: Netlify's deploy docs say to drag the project's updated output folder to the dropzone at the bottom of the site's Deploys page. For a brand-new site, drop it on Netlify Drop or the drag and drop area of your team's Projects page.
    • With the Netlify CLI: netlify deploy --prod --dir=dist.
  3. Open the live site in a private window and reload with the console open. The error should be gone.

Does Netlify build it for me? It depends on how you deploy. Netlify's deployment guide says that manual CLI deploys (netlify deploy) never run your build command — whatever is in the folder goes live. It also says that Netlify Drop, when you're logged in, detects your framework and runs the build before publishing, while when you're not logged in, files are published exactly as they are. Older forum answers say drag and drop never builds; that was true before. If you're not sure what happened in your case, uploading the already-built dist folder works either way.

If your app uses environment variables (a Supabase address, for example), they must be available when you run npm run build locally — usually in a .env file in the project folder. Otherwise you'll fix this error and run into the next one: see supabaseUrl is required after deploy.

Fix 2: Deploy from Git instead

Building by hand works, but you have to repeat it for every change. Connecting a Git repository lets Netlify build your app on every push. Netlify's guide calls this "the right choice for any project with a repo behind it".

  1. Put your project in a GitHub repository (create a repository and upload the project files, or use your builder's GitHub integration if it has one).
  2. In Netlify, choose to add a new project from an existing repository and select it.
  3. In the build settings, set:
    • Build command: npm run build
    • Publish directory: dist
  4. Add any environment variables your app needs (for example VITE_SUPABASE_URL) in the project's environment variable settings.
  5. Deploy.

For an existing project, these fields are under Project configuration → Developer settings → Continuous deployment → Build settings (per Netlify's build configuration docs). You can also keep them in a netlify.toml file in the root of your repository, which Netlify's docs show like this:

[build]
  command = "npm run build"
  publish = "dist"

Netlify's docs note that settings in the configuration file override the ones in the UI.

Fix 3: Deployed straight from Bolt

If you used Bolt's own button to publish to Netlify, Bolt does the build and upload. When the live site is blank anyway:

  1. Publish again from Bolt, so the latest code is built.
  2. In Netlify, open the site → Deploys → the latest production deploy, and look at the Deploy File Explorer under the deploy log. Netlify's page not found guide describes this explorer as the way to check which files were actually deployed.
  3. Check that there's an index.html and an assets folder containing .js files.

If no JavaScript was deployed, the problem is on Bolt's side. In one forum thread, buttons and sliders worked in Bolt but not on Netlify; Netlify support found that no JavaScript file had been deployed at all, and pointed out that since Bolt was deploying the site, Bolt was responsible for that file. In that case, contact Bolt's support, or switch to Fix 2 so you control the build.

Also check whether Netlify itself is having an incident on our Netlify status page before you change anything.

Same error on other hosts

The same message can appear on Vercel, GitHub Pages or any other host, with a different cause: the server sends the wrong file because the address is wrong. For example, if base in vite.config points to a subfolder that doesn't exist on your host, requests for your JavaScript get an HTML page back instead (MIME type text/html). That case is covered in White screen after deploying to Vercel.

If the page doesn't show your app at all but Netlify's "Page not found" message, see Netlify "Page Not Found" after deploy. And for other Bolt deployment problems — environment variables, sign-in redirects, routing — see Why is my Bolt.new app not working after deploy.

FAQ

What does "Expected a JavaScript module script" mean?
The page asked for a JavaScript file, and the server answered with something that isn't JavaScript — for example a TypeScript source file like main.tsx sent as application/octet-stream. Browsers refuse to run module scripts with the wrong type, so nothing on the page starts.
Why does my app work in Bolt but not on Netlify?
Bolt's preview runs a development server that turns your source code into JavaScript on the fly. A live site has no such server: it needs the output of npm run build (the dist folder). If the source folder was uploaded instead, the browser gets main.tsx and stops.
Does Netlify build my project when I drag and drop a folder?
According to Netlify's docs, Netlify Drop detects your framework and runs the build when you're logged in; when you're not logged in, files are published exactly as they are. Deploys with the netlify deploy command never run your build. Dropping the built dist folder works in every case.
How do I know which files Netlify actually deployed?
Open your site in Netlify, go to Deploys, open the latest production deploy and look at the Deploy File Explorer under the deploy log. You should see index.html and an assets folder with .js files.

Fixed it? Run a free Pingbuddy checkup on your live site. It shows whether your site answers and how fast, when your SSL certificate and domain expire, whether your Supabase project is paused and whether secret keys are visible in your public code.

Run free checkup →