---
title: "vite preview returns 404 for the module script of a subpath build that static hosts serve fine"
url: "https://www.dariuszparys.com/notes/vite-preview-404-for-subpath-build"
author: "Dariusz Parys"
published: 2026-11-11T00:00:00.000Z
description: "vite preview answered 404 for the entry script of a build with a base path, while a plain static server and GitHub Pages served the same files without errors."
---

# vite preview returns 404 for the module script of a subpath build that static hosts serve fine

## Context

A Vite 8 app built with `base: '/my-app/'` to deploy as a GitHub Pages project site. `vite preview` showed a blank page: the HTML and CSS loaded, but the hashed entry JS came back 404.

## Insight

A blank page from `vite preview` after setting `base` doesn't mean the build is broken. Check with a plain static server before you debug the config.

- `curl` got 200 for the same JS URL. The 404 only appeared when the request carried `Sec-Fetch-Dest: script`, which browsers send for module scripts. I didn't track down the cause inside Vite.
- The same `dist/` served from a plain static server loaded every asset with no console errors. The real GitHub Pages deploy worked too.

## Reproduce

```bash
curl -s -o /dev/null -w "%{http_code}\n" http://localhost:4173/my-app/assets/index-<hash>.js
# 200
curl -s -o /dev/null -w "%{http_code}\n" -H 'Sec-Fetch-Dest: script' http://localhost:4173/my-app/assets/index-<hash>.js
# 404
```

## Check a subpath build instead

Put `dist/` in a folder named after the base path and serve its parent:

```bash
mkdir -p /tmp/pages-root
cp -R dist /tmp/pages-root/my-app
cd /tmp/pages-root && python3 -m http.server 8000
# open http://localhost:8000/my-app/
```
