Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Vite cannot find the entry file named in index.html

ErrorFailed to load url /src/main.jsx (resolved id: /src/main.jsx). Does the file exist?

Short answer

Vite starts from index.html and loads the module named in its script tag, resolving a path that starts with a slash from the project root. The error means nothing exists at that path. The file has another name or extension, its letter case differs, or Vite was started in a different folder than the one holding index.html.

  • Applies to Vite 7, Vite 8, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Compare the script tag in index.html with the real files and with the folder you started Vite from.

    pwd
    grep -n "script" index.html
    ls src
  2. 2Match what you see, then jump to its fix

    1. 1ls src shows main.tsx, main.js or Main.jsx while index.html says /src/main.jsxThe file name or extension differs from the script tagFix
    2. 2pwd is a parent or a sibling of the folder that contains index.html and vite.configVite was started from the wrong folderFix
    3. 3Works on macOS or Windows, fails on Linux, in Docker or in CILetter case differs between the HTML and the fileFix

What does the error look like?

  • Failed to load url /src/main.jsx (resolved id: /src/main.jsx). Does the file exist?

Cause 1 of 3

The file name or extension differs from the script tag

1Check

Vite takes the path in index.html literally. Absolute URLs are resolved against the project root, so /src/main.jsx must be a file at that exact name. Converting a project to TypeScript or renaming the file leaves the old name behind in the HTML.

ls src | grep -i main
grep -n "type=\"module\"" index.html

2Fix

Make the script tag name the file that exists, including extension and letter case.

<!-- index.html -->
<script type="module" src="/src/main.tsx"></script>

3Verify

Restart the dev server and reload the page; the error is gone.

npm run dev

Confirmed by vite.dev

Did this fix it?

Cause 2 of 3

Vite was started from the wrong folder

1Check

Running vite uses the current working directory as the project root, so /src/main.jsx is looked up under that directory.

pwd
ls index.html vite.config.*

2Fix

Change into the project folder first, or pass the root on the command line, and keep the config file with that root.

cd my-app
npm run dev

3Verify

The dev server prints its local URL and the page renders.

curl -I http://localhost:5173/src/main.jsx

Confirmed by vite.dev

Did this fix it?

Cause 3 of 3

Letter case differs between the HTML and the file

1Check

A file system that ignores case hides a mismatch such as Main.jsx versus main.jsx. Linux treats them as two names. Vite's troubleshooting guide lists this as a cause of ENOENT and 'Module not found' errors in Linux builds.

git ls-files src | grep -i main

2Fix

Rename the file or fix the reference so the case is identical, then tell git about the rename if the OS hid it.

git mv src/Main.jsx src/main.jsx

3Verify

Build on Linux or inside the container.

npm run build

Confirmed by vite.dev

Did this fix it?

How do I stop it coming back?

  • Keep index.html at the project root next to vite.config and package.json.
  • When renaming the entry file, search index.html in the same commit.
  • Run the build in CI on Linux so case mismatches fail before release.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.