Vite cannot find the entry file named in index.html
Failed 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.
Fix it fast
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 src2Match what you see, then jump to its fix
- 1
ls 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
pwd is a parent or a sibling of the folder that contains index.html and vite.configVite was started from the wrong folderFix - 3
Works on macOS or Windows, fails on Linux, in Docker or in CILetter case differs between the HTML and the fileFix
- 1
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.html2Fix
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 devConfirmed by vite.dev
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 dev3Verify
The dev server prints its local URL and the page renders.
curl -I http://localhost:5173/src/main.jsxConfirmed by vite.dev
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 main2Fix
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.jsx3Verify
Build on Linux or inside the container.
npm run buildConfirmed by vite.dev
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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix