vite lastVerified: 2026-05-08

Failed to resolve import "<path>" from "<file>". Does the file exist?

Failed to resolve import — Vite import path resolution

On this page
  1. What causes this error
  2. How to fix it manually
  3. Copy this prompt into your AI coding agent
  4. Why this prompt works
  5. Variants by symptom
  6. Related errors and tools

What causes this error

Vite’s dev server emits this message when its resolver walks the import string from the calling file’s directory and does not find a matching file on disk. Unlike the TypeScript-flavoured “Cannot find module” error, this one is purely a filesystem question — the file genuinely is not where the import says it is. Five distinct cases produce the message, and they fail in different ways across operating systems.

Case one: the import path omits the file extension and resolves to a folder that lacks an index.ts. Vite is stricter than Webpack here — import x from './utils' requires either ./utils.ts or ./utils/index.ts to exist. Case two: the alias declared in vite.config.ts resolve.alias does not match the import — a typo like @components/Button when the alias is @/components looks fine to a human reading both lines but Vite’s resolver treats them as unrelated prefixes. Case three: the file was renamed or moved (often by an earlier AI-agent edit that touched files outside its declared scope) and the import was not updated — a git log --diff-filter=R reveals the rename. Case four: case-sensitivity drift between dev environments — Button.tsx and button.tsx resolve identically on macOS’s APFS default and on Windows’s NTFS, but break on Linux’s ext4 — which is exactly the surface Cloudflare Pages, GitHub Actions, and most CI runners present. Case five: a monorepo workspace package was added to package.json but pnpm install has not yet linked the package into node_modules.

How to fix it manually

Read the full error — Vite prints both the import string and the absolute path of the file making the import. Run ls -la <directory> and confirm the target file exists with the expected case. Run git log --diff-filter=R --follow -- <suspected old path> to detect a historical rename. Run pnpm install and pnpm dev again to rule out a stale lockfile or unlinked workspace. If the alias is at fault, open vite.config.ts and confirm resolve.alias matches what the import says.

Copy this prompt into your AI coding agent

vite-failed-to-resolve-import-fix-prompt.md
# Goal
Fix this Vite "Failed to resolve import" error using the smallest safe change.
Diagnose which of five cases applies (extension / alias / rename / case-sensitivity /
unlinked workspace) before patching anything.

# Context

The full error message:

<paste the Vite error including the from "<file>" path and the unresolved import string>

The OS where it fails: <macOS / Linux / Windows / CI>
The OS where it works: <macOS / Linux / Windows / not applicable>

# In-scope

- The single failing import statement
- vite.config.ts resolve.alias entries
- The file referenced by the import path (existence and casing)
- package.json workspace declarations if monorepo

# Out-of-scope

- Renaming components or splitting modules
- Replacing Vite with another bundler
- Refactoring the import-export structure of unrelated files
- Adding new build steps

# Verification

Run `pnpm dev` and reload the page that triggered the error — confirm no console errors.
Run `pnpm build` and confirm production build completes with exit code 0.
Run `ls -la <directory>` and confirm the target file exists with the casing the import uses.

# Output format

1. One sentence: which of five cases this is.
2. The diff (only changed files).
3. The verification output, last 10 lines.
4. One line: any sibling imports you noticed pointing at the same broken target but did NOT change.

Why this prompt works

The five-case enumeration is the prompt’s load-bearing element — it short-circuits the “refactor everything” failure mode. Naming the OS where the error fails versus where it works catches the case-sensitivity case directly: if the answer is “fails on Linux CI, works on macOS dev”, the agent jumps straight to the casing fix without exploring the other four. The “sibling imports you did NOT change” line in Output format is deliberate friction — it forces the agent to surface candidates for a follow-up commit rather than silently rewriting them.

Variants by symptom

SymptomDiagnostic command
Works on macOS dev, fails on Linux CIgit ls-files then grep the basename (case clash)
Fails after renaming a filegit log --diff-filter=R --follow -- <path>
Alias prefix mismatchgrep resolve.alias vite.config.ts
Workspace package not linkedpnpm install && pnpm -r build
Import omits extension on barrel-less folderAdd index.ts or specify the extension explicitly