How to Fix “Failed to resolve import” in Vite
When the Vite dev server shows Failed to resolve import "./Foo" from "src/App.tsx". Does the file exist?, it means the file ./Foo imported in src/App.tsx cannot be found. Make the letter case of the file name, or the import path (the folder location), match the actual file, and the error goes away.
This is the cause and fix for the case where you run npm run dev, open a React app, and a dark error overlay appears in the browser, with an error in the terminal too. In my test environment I triggered this error with two kinds of mistakes, and I copied the messages shown in the browser and terminal as they were. For both, I also confirmed that the error disappears after the fix.
The test environment was Ubuntu 24.04 (filesystem ext4), Node.js 22.23.4, Vite 8.3.8, @vitejs/plugin-react 6.3.0, React 19.3.1, and TypeScript 7.0.2. I created the project with the react-ts template from npm create vite@latest. I opened the browser with Chromium from Playwright 1.63.0. I did not test on Windows or macOS.
The message when the letter case of the file name is different
The first case is a mistake where the file is still named foo.tsx in lowercase, but App.tsx imports it as ./Foo with an uppercase F.
// src/App.tsx
import Foo from './Foo'
function App() {
return (
<main>
<h1>App</h1>
<Foo />
</main>
)
}
export default App
// src/foo.tsx
function Foo() {
return <p>Foo を読み込めました</p>
}
export default Foo
I started the dev server with npx vite and opened it in the browser. The page body stayed empty, and the following error overlay appeared on top.

The text shown was as follows (I omitted the at lines of the stack trace).
[plugin:vite:import-analysis] Failed to resolve import "./Foo" from "src/App.tsx". Does the file exist?
/path/to/app/src/App.tsx:1:16
1 | import Foo from "./Foo";
| ^
2 | var _jsxFileName = "/path/to/app/src/App.tsx";
3 | import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
Click outside, press Esc key, or fix the code to dismiss.
You can also disable this overlay by setting server.hmr.overlay to false in vite.config.ts.
The terminal running the dev server showed the same content as Internal server error (I omitted the at lines of the stack trace).
6:45:04 PM [vite] Internal server error: Failed to resolve import "./Foo" from "src/App.tsx". Does the file exist?
Plugin: vite:import-analysis
File: /path/to/app/src/App.tsx:1:16
1 | import Foo from "./Foo";
| ^
2 | var _jsxFileName = "/path/to/app/src/App.tsx";
3 | import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
After that, the same content as (client) Pre-transform error: Failed to resolve import "./Foo" from "src/App.tsx". Does the file exist? appeared several times. The number of times differed with each startup, but the content was always the same.
In the test, I placed the project in a folder named /path/to/app and ran it there, so the paths are shown as they were.
Where to look in the message
In Failed to resolve import "./Foo", the "./Foo" is the string written in the import. from "src/App.tsx" is the file that contains that import. In the Vite 8.3.8 code, this file location is shown as a path relative to the folder where the dev server was started.
1:16 points to the position of "./Foo" on line 1 (the column is counted from 0; in the vite build message shown later, the same position appears as 1:17). The lines 2 and 3 below it are the code after Vite's transformation, not the App.tsx you wrote (line 2 there is blank). You only need to look at line 1.
When the extension is omitted, as in ./Foo, Vite tries .mjs, .js, .mts, .ts, .jsx, .tsx, and .json in turn (see the resolve.extensions entry in the official documentation). This error means that none of them, including src/Foo.tsx, was found. On Linux (ext4), which is my test environment, file names are case-sensitive, so ./Foo does not match foo.tsx.
Renaming the file to match the import makes the error go away immediately
With the browser page still open, I renamed the file to Foo.tsx to match the import.
$ mv src/foo.tsx src/Foo.tsx
The terminal showed [vite] (client) page reload src/Foo.tsx, the browser page reloaded automatically, and the error overlay disappeared. The page displayed the following.

When I stopped the dev server, started it again, and then opened the page, there was no error either.
The Vite troubleshooting guide notes that when a project created on a case-insensitive filesystem (Windows, macOS) is built on a case-sensitive one (Linux), errors such as Module not found can occur. Make sure the letter case in your imports exactly matches the file name.
The same message also appears when the folder location is wrong
The second case is a mistake where the file is placed at src/components/Foo.tsx, but App.tsx still imports it as './Foo'. The result of ls after moving the file is as follows.
$ ls src src/components
src:
App.tsx
components
index.css
main.tsx
src/components:
Foo.tsx
When I opened the page with the dev server, the browser and terminal showed exactly the same message as in the letter-case mistake (except for the time in the terminal). The message alone does not tell you whether the problem is the name or the location. Check whether a file with that name really exists at the place ./Foo points to, relative to the file that contains the import (src/App.tsx).
I fixed line 1 of App.tsx to match the file's location.
import Foo from './components/Foo'
After saving, the terminal showed [vite] (client) page reload src/App.tsx, the error overlay in the browser disappeared, and a line saying that Foo was loaded was displayed.
The message is different in a build
The npm run build of the react-ts template runs tsc -b && vite build. When I ran it with the same mistake, the TypeScript compiler (tsc), which runs first, stopped, and the build never reached Vite (exit code 1).
$ npm run build
> app@0.0.0 build
> tsc -b && vite build
src/App.tsx(1,17): error TS2307: Cannot find module './Foo' or its corresponding type declarations.
When I ran only vite build, it stopped with the following message in Vite 8.3.8. The exit code was 1. I omitted the final stack trace (from the at lines through the closing }).
vite v8.3.8 building client environment for production...
transforming...
✓ 16 modules transformed.
✗ Build failed in 90ms
error during build:
Build failed with 1 error:
[UNRESOLVED_IMPORT] Could not resolve './Foo' in src/App.tsx
╭─[ src/App.tsx:1:17 ]
│
1 │ import Foo from "./Foo";
│ ───┬───
│ ╰───── Module not found.
│
│ Help: 'src/App.tsx' is imported by the following path:
│ - src/App.tsx
│ - src/main.tsx
│ - index.html
───╯
Instead of Failed to resolve import from the dev server, the build shows Could not resolve './Foo' in src/App.tsx and Module not found., but both point to the same import. When the file was named foo.tsx in lowercase, the error type was the same [UNRESOLVED_IMPORT] (the message shows the path written in the import).
When I changed the import to './components/Foo', vite build finished with ✓ built in 169ms (exit code 0), and npm run build also passed tsc -b and finished the build. When I renamed the file back to Foo.tsx, vite build finished in the same way.





