The Vite dev server takes a long time to start or load the first page
npm run dev takes tens of seconds before the page appearsShort answer
Vite does most of its work when the browser first asks for files. Slowness usually comes from browser extensions, a slow plugin hook, extension guessing on imports, barrel files, or a long request chain. Profile first with vite --debug plugin-transform, then fix the one that shows up.
Fix it fast
1Find out which cause you have
Print the transform time of each file so you see the slow part rather than guess.
npx vite --debug plugin-transform2Match what you see, then jump to its fix
- 1
The same project loads quickly in a private windowBrowser extensions or disabled cacheFix - 2
--profile shows time in buildStart, config or configResolvedA plugin does heavy work in a startup hookFix - 3
Many files are fetched for a page that uses few of themExtension guessing and barrel filesFix - 4
One big component delays everything it importsA request waterfall of slow filesFix
- 1
What does the error look like?
npm run dev takes tens of seconds before the page appearsThe first page load is slow and later loads are fast
Cause 1 of 4
Browser extensions or disabled cache
1Check
Extensions can interfere with requests, and Disable Cache in dev tools forces every file to be fetched again.
# open the app in a private window and compare load time2Fix
Use a browser profile without extensions for development and turn Disable Cache off.
# dev tools > Network > untick Disable cache3Verify
Reload the page twice; the second load should be clearly faster.
# compare the load time in the Network tabConfirmed by vite.dev
Cause 2 of 4
A plugin does heavy work in a startup hook
1Check
These hooks are awaited during startup, so long work in them delays the first page.
npx vite --profile2Fix
Move heavy work out of those hooks and import large dependencies only when needed. In resolveId, load and transform, check the id before doing the full work.
// inside the plugin
const { heavyTransform } = await import('heavy-lib')3Verify
Start again and compare the profile.
npx vite --debug plugin-transformConfirmed by vite.dev
Cause 3 of 4
Extension guessing and barrel files
1Check
Extensionless imports make Vite try each extension in resolve.extensions. A barrel file (an index that re-exports many files) makes Vite fetch and transform every file it re-exports.
grep -rn "from './utils'" src | head2Fix
Write the file extension in imports and import from the source file instead of the barrel.
// before
import { slash } from './utils'
// after
import { slash } from './utils/slash.js'3Verify
Restart and check that fewer files are transformed.
npx vite --debug transformConfirmed by vite.dev
Cause 4 of 4
A request waterfall of slow files
1Check
A slow file blocks the files it imports until it is transformed.
npx vite --debug transform2Fix
Warm up the frequently used files at server start.
export default defineConfig({
server: {
warmup: {
clientFiles: ['./src/components/BigComponent.vue'],
},
},
})3Verify
Open the app and compare time to first render.
npm run devConfirmed by vite.dev
How do I stop it coming back?
- Warm up only files that are used often; warming everything slows the start itself.
- Prefer plain CSS over Sass, Less or Stylus where you can.
- Import SVGs as URLs instead of turning each into a framework component.
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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix