localhost:5173 / clear-cache

Clearing the Vite dependency cache

Vite caches pre-bundled dependencies in node_modules/.vite — delete that directory or start with --force to rebuild it.

Two ways, same result

The flag tells the optimizer to ignore what it has and re-bundle. Deleting the directory does the same thing more bluntly.

bash
$ npm run dev -- --force

# or
$ rm -rf node_modules/.vite

What is in there

Your dependencies, pre-bundled. Vite converts packages to ESM once and reuses the result, which is a large part of why the dev server starts as fast as it does. The location is node_modules/.vite by default and follows cacheDir if you move it.

When it genuinely helps

  • You changed a dependency by hand — npm link, a patch, an edit inside node_modules.
  • You switched branches and package.json went with it.
  • A package updated but the browser keeps loading the old code.
  • Errors that point inside node_modules and survive a restart.

When it does not

A stale page is more often the browser than the server. Check a hard reload with the cache disabled, and check whether a service worker from an earlier project is still serving that origin — on localhost they outlive the project that installed them, and they will happily serve a build from weeks ago.

Not the browser cache

Two different caches with the same nickname. node_modules/.vite lives on disk and belongs to the dev server; the browser cache lives in the browser. Clearing one does nothing for the other.

# faq

Questions

Where does Vite store its cache?

In node_modules/.vite, or wherever cacheDir points.

What does --force do?

It makes the dependency optimizer ignore the cache and re-bundle.

Is it safe to delete node_modules/.vite?

Yes. It is rebuilt on the next start — that start is just slower.

The page is still stale after clearing the cache.

Then it is the browser. Hard reload with the cache disabled, and check for a leftover service worker on localhost.

# next

Related

# sources

Checked against the Vite documentation on 2026-09-11.