Maaz Zindani

Loading the index…

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

Vite cannot find a relative import such as ./store in main.ts

Your error

Internal server error: Failed to resolve import "./store" from "src/main.ts". Does the file exist?1 more line it can show

Fix it fast

Most common cause, 1 of 4

Nothing exists at that path yet

Create the module where the import expects it, or change the import to the folder where the file really lives.

Fix
mkdir -p src/store
touch src/store/index.ts
# write and export the store in src/store/index.ts
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

On Vite 7 and 8, Failed to resolve import ... Does the file exist? shows up when a relative path like ./store matches nothing: not the path as written, not with a resolve.extensions ending, and not a folder index. Create the missing file, add the .vue extension, import the file inside the folder by name, or fix the letter case.

  • Applies to Vite 8.3, Vite 7, Vue 3.5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

List the folder of the importing file without regard to case. It shows at once whether the target is missing, has another extension, is a folder, or is spelled with different capitals.

Run this first
ls -la src | grep -i store
ls -la src/store

Then find the line you see in this list and open its fix:

  1. 1Nothing exists at that path yetNeither listing shows a file or folder with that name
  2. 2The import leaves out .vue or another non-default extensionThe file exists as HelloWorld.vue, but the import names ./components/HelloWorld
  3. 3The path is a folder that has no index file Vite can usels src/store shows a folder whose main file is named something like store.ts or index.vue
  4. 4The capitals in the import differ from the name on diskThe app runs on macOS or Windows, and the same commit fails on Linux, in Docker or in CI

What does the error look like?

  • Internal server error: Failed to resolve import "./store" from "src/main.ts". Does the file exist?
  • Failed to resolve import "./components/HelloWorld" from "src/App.vue". Does the file exist?

Cause 1 of 4

Nothing exists at that path yet

You seeNeither listing shows a file or folder with that name

Check

Failed to resolve import names a relative path that simply does not exist when the module was never created in this project. Code copied from a tutorial or another project may import a module, such as a store or router setup, that this project never got. Search the whole tree in case the file sits somewhere else.

Check
find src -iname "store*"

Fix

Create the module where the import expects it, or change the import to the folder where the file really lives. The path is relative to the importing file, not to the project root.

Fix
mkdir -p src/store
touch src/store/index.ts
# write and export the store in src/store/index.ts

Verify

Save the file. The error overlay goes away once the import resolves; if it stays, restart the dev server.

Verify
npx vite

Confirmed by github.com

Did this fix it?

Cause 2 of 4

The import leaves out .vue or another non-default extension

You seeThe file exists as HelloWorld.vue, but the import names ./components/HelloWorld

Check

Failed to resolve import "./components/HelloWorld" appears for a file named HelloWorld.vue because, without an extension, Vite only tries .mjs, .js, .mts, .ts, .jsx, .tsx and .json. Single-file components are not in that list. Vite's docs also advise against dropping the .vue part, since that can get in the way of editor and type support.

Check
grep -rnE "from '\.{1,2}/[^']*'" src | grep -vE "\.[a-z]+'"

Fix

Write the extension in every import of a component file.

Fix
// before
import HelloWorld from './components/HelloWorld'
// after
import HelloWorld from './components/HelloWorld.vue'

Verify

Reload the page; the component renders and the overlay is gone.

Verify
npx vite

Confirmed by vite.dev

Did this fix it?

Cause 3 of 4

The path is a folder that has no index file Vite can use

You seels src/store shows a folder whose main file is named something like store.ts or index.vue

Check

Failed to resolve import "./store" can point at a folder that exists but holds no usable index file. When the path is a directory, Vite reads a package.json inside it if there is one, and otherwise looks only for index plus one of the resolve.extensions. A folder holding store.ts, or an index.vue, does not count.

Check
ls src/store

Fix

Import the file inside the folder by its name, or add an index.ts that re-exports it.

Fix
// either
import store from './store/store'

// or src/store/index.ts
export { default } from './store'

Verify

Restart Vite and load the page that uses the import.

Verify
npx vite

Confirmed by github.com

Did this fix it?

Cause 4 of 4

The capitals in the import differ from the name on disk

You seeThe app runs on macOS or Windows, and the same commit fails on Linux, in Docker or in CI

Check

Failed to resolve import shows up on Linux, in Docker or in CI, but not on a laptop, when the capitals in the import differ from the name on disk. Windows and macOS file systems treat names without regard to case, so ./Store finds store/index.ts there. Linux compares case, and the lookup fails. The case-insensitive listing from the first step shows the real spelling.

Check
git ls-files src | grep -i store

Fix

Change the import so every letter matches the spelling on disk.

Fix
// before
import store from './Store'
// after
import store from './store'

Verify

Run the build on Linux or in the CI job that failed.

Verify
npx vite build

Confirmed by vite.dev

Did this fix it?

How do I stop it coming back?

  • Write file extensions on imports of .vue, .svelte and other component files.
  • Keep folder imports to folders that have an index.ts or index.js.
  • Let CI build on a Linux runner, where a wrongly capitalised import breaks the job instead of production.

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.

Next step

Want this handled for good?

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