Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Vite build stops with [vite:load-fallback] Could not load a file

Error[vite:load-fallback] Could not load /src/components/Header (imported by src/App.tsx)

Short answer

The message names two files: the one Vite could not read and the file that imports it. Open the importing file and compare the import with the real file name on disk. The usual causes are a different letter case that only fails on Linux, or an alias that points at a relative path instead of an absolute one.

  • Applies to Vite 7, Vite 8, Node.js 22, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Copy the path from the error and list what is really in that folder. Compare name, letter case and extension with the import in the file named after 'imported by'.

    ls -la src/components/
    git ls-files src/components | head -n 30
  2. 2Match what you see, then jump to its fix

    1. 1Works on your Windows or macOS machine, fails in CI, Docker or a Linux server with ENOENTImport and file name differ only by letter caseFix
    2. 2The failing path starts with your alias target, written as a relative string, for example ../srcAn alias points at a relative pathFix

What does the error look like?

  • [vite:load-fallback] Could not load /src/components/Header (imported by src/App.tsx)
  • ENOENT: no such file or directory
  • Module not found

Cause 1 of 2

Import and file name differ only by letter case

1Check

Vite's troubleshooting page lists this as the cause of ENOENT and Module not found when a project built on Windows or macOS is built on Linux. Check that git stores the same case as the import.

git ls-files | grep -i "header"
grep -rn "components/header" src

2Fix

Make the import match the file name exactly. If the file was renamed only by case, rename it through git so the index changes too.

git mv src/components/header.tsx src/components/Header.tsx
# import { Header } from './components/Header'

3Verify

Build again on the Linux machine that failed.

npx vite build

Confirmed by vite.dev

Did this fix it?

Cause 2 of 2

An alias points at a relative path

1Check

Read resolve.alias in the Vite config. Vite uses a relative alias value as it is written and does not turn it into a file system path.

grep -n -A6 "alias" vite.config.*

2Fix

Give the alias an absolute path built from the config file location.

import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'

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

3Verify

Restart the dev server and run a build.

npx vite build

Confirmed by vite.dev

Did this fix it?

How do I stop it coming back?

  • Run the build on Linux in CI so a case mismatch fails before release.
  • Use git mv for renames that only change letter case.
  • Write alias targets as absolute paths with fileURLToPath.

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.