Skip to content
nkNilay Kabariya

Entry No.010·Fixes··1 min read

Fix: Vite “Failed to resolve import” for @ alias imports

Vite can't find an @/ import until the alias is in vite.config. Why tsconfig paths alone don't help, and the new Vite 8 Rolldown wording. Reproduced.

by Nilay#vite#javascript#typescriptFIXED

The error, verbatim

Jump to the fix ↓
[vite] Internal server error: Failed to resolve import "@/utils/hello"
from "src/main.js". Does the file exist?

Error: [vite]: Rolldown failed to resolve import "@/utils/hello" from ".../src/main.js"

Tested on

Vite
8.3.0 (Rolldown)
Node
24.14.0
OS
Windows 11 Pro
Contents
  1. The fix01
  2. What didn’t work02
  3. Same error, different wording03
  4. Why it happens04

The fix

@/ isn’t a real path. It’s an alias you have to define in vite.config.js (or .ts):

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

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

Using TypeScript? Keep the matching paths in tsconfig.json too. That entry is only for your editor and type checker, as the next section shows.

What didn’t work

Same error, different wording

  • Dev server (vite): Failed to resolve import "…" from "…". Does the file exist?, shown in the terminal and as a red overlay in the browser.
  • Build in Vite 8: Rolldown failed to resolve import. Vite 8 bundles with Rolldown, so older answers that say “Rollup failed to resolve import” are describing the same problem.
  • A typo in a relative path (./utils/helo) gives a different build message: [UNRESOLVED_IMPORT] Could not resolve './utils/helo'. Check the spelling and extension.

Why it happens

Vite resolves bare paths through node_modules and relative paths from the importing file. @/... is neither, so without an alias Vite looks for a package literally named @/utils. It fails, and your app never loads.

— N.K., end of entry No.010

Useful? Pass it on:Post on X

Related entries

  1. No.002

    Fix: __dirname is not defined in ES module scope (Node 24)

    ES modules don't have __dirname or __filename. The one-line modern fix (import.meta.dirname) and the fallback for older Node, both run on Node 24.

    > console.log(path.join(__dirname, "data.json"));

    FIXED1 min
  2. No.001

    Fix: “Cannot use import statement outside a module”

    The fix for Node and the browser. On Node 24 a plain .js file now often just works, so here's exactly when the error still happens. Reproduced in both.

    > SyntaxError: Cannot use import statement outside a module

    FIXED1 min
  3. No.009

    Fix: “trying to use tailwindcss directly as a PostCSS plugin”

    Tailwind CSS v4 moved its PostCSS plugin to a separate package. The two-line change to postcss.config.js, reproduced and verified.

    > Error: It looks like you're trying to use `tailwindcss` directly as a PostCSS

    FIXED1 min

Post card · Newsletter

Get the next fix in your inbox.

One short email when a new entry is published. No spam, never shared, and you can leave any time.

— Nilay

or follow by RSS

By subscribing you agree to the privacy note. One click to leave.

tip: paste the exact error text