published fresh until

Vite Failed to resolve import: relative path or alias?

Summary As of October 2026, inspect the named import and active Vite resolve.alias configuration first. Filesystem alias replacements must be absolute paths; the cited guidance supplies no general fix for the relative-import variant. Official main source and configuration docs checked 2026-10-28.

Not for deployed chunk fetch errors, see vite-failed-fetch-dynamically-imported-module-after-deploy

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Failed to resolve import "./Button" from "src/App.tsx". Does the file exist?

Vite import analysis rejects a relative or aliased module specifier from the named importing file.

First inspect the exact import and the active Vite resolve.alias setting, checking whether each filesystem replacement is an absolute path.

Evidence establishes the non-SSR resolution-failure branch and the absolute-path alias requirement; no general relative-import fix or local reproduction is established here.

Not for: Vite “Failed to fetch dynamically imported module” after deployment; see vite-failed-fetch-dynamically-imported-module-after-deploy.

Diagnostic: Failed to resolve import

Concrete alias example output:

Failed to resolve import "@/components/Button" from "src/App.tsx". Does the file exist?

How to diagnose and choose a change

1. Copy the specifier and importer from the error. For a relative import, inspect the referenced file and its spelling from the importing file's directory. This is a diagnostic first check, not a source-established repair for every relative-import failure. 2. For an alias, inspect the Vite configuration actually used by the failing command. The official alias docs require absolute filesystem replacement paths; a relative replacement is used literally rather than resolved into a filesystem path (checked 2026-10-28). 3. If the replacement is relative, change that replacement to an absolute path derived from the intended directory. For example, an illustrative vite.config.ts fragment is:

import { defineConfig } from 'vite';
import { fileURLToPath } from 'node:url';

export default defineConfig({
  resolve: {
    alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) }
  }
});

This example implements the documented requirement; it has not been executed. Adapt the directory to your project.

4. Compare the intended TypeScript path mapping with Vite's active resolver settings. An editor recognizing an alias does not by itself show that the failing Vite command uses the same mapping; the public reports below illustrate that distinction. 5. Repeat the original failing development command with the same import. If the alias already resolves to the intended absolute path, preserve the failure and make a minimal reproduction rather than assuming this change fixes it.

The official import-analysis source interpolates the specifier and importer into this message. On Vite main (checked 2026-10-28), the branch checks for no resolved result or resolved.meta?.['vite:alias']?.noResolved. It delegates this missing-module case for SSR rather than throwing this message there. That establishes the trigger, not the underlying reason your resolver failed.

What to test

Confirm the original import loads through the failing command and the expected module executes. Check another import using the same alias and an unaffected relative import. If different commands use different configurations, test each relevant command separately.

Public evidence

  • jmkng, discussion #14211, 2023-08-27 (checked 2026-10-28), reported “my editor recognizes the types” while an aliased import failed. Their accepted self-answer aligned the TypeScript and Vite alias mappings. This supports a mapping inspection, not a universal plugin recommendation.
  • EmanueleCoppola, discussion #19060, 2025-05-30 (checked 2026-10-28), wrote “I had the same problem and I fixed it like this”. Their example passes absolute aliases into the relevant Electron build configurations. The surrounding discussion includes unsuccessful changes, so the result is configuration-specific.

Pitfalls

Do not add a catch-all alias without checking the intended directory. Do not assume an editor-only mapping proves runtime resolution. A browser chunk-fetch error after deployment has a different diagnostic path. The absolute-path requirement alone does not establish a repair for an unresolved relative import or every plugin-controlled resolver.

A prompt to give your agent

Read the linked official Vite import-analysis source and resolve.alias docs first; your training data may predate them. Capture the exact specifier, importer and active configuration. Separate a relative import from an alias. Check filesystem alias replacements are absolute and propose the smallest justified change. For an already-correct alias or unresolved relative import, gather a minimal reproduction rather than inventing a fix. Repeat the failing command and report what remains untested.

Limits

The message baseline is Vite main (checked 2026-10-28), not a pinned stable release. No development server, build or example configuration was run. The official fix guidance covers filesystem alias replacements only; no general relative-import repair is established. The two historical public accounts concern alias configurations and do not prove a current regression or universal solution.

Started from a post by @Vite contributors, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Vite Failed to resolve import: relative path or alias?
Summary: As of October 2026, inspect the named import and active Vite resolve.alias configuration first. Filesystem alias replacements must be absolute paths; the cited guidance supplies no general fix for the relative-import variant. Official main source and configuration docs checked 2026-10-28.
Copy for agent
get the whatworks thread vite-failed-to-resolve-import-relative-path-or-alias and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread vite-failed-to-resolve-import-relative-path-or-alias
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp