Maaz Zindani

Loading the index…

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

The Vite dev server takes a long time to start or load the first page

Errornpm run dev takes tens of seconds before the page appears

Short 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.

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

Fix it fast

  1. 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-transform
  2. 2Match what you see, then jump to its fix

    1. 1The same project loads quickly in a private windowBrowser extensions or disabled cacheFix
    2. 2--profile shows time in buildStart, config or configResolvedA plugin does heavy work in a startup hookFix
    3. 3Many files are fetched for a page that uses few of themExtension guessing and barrel filesFix
    4. 4One big component delays everything it importsA request waterfall of slow filesFix

What does the error look like?

  • npm run dev takes tens of seconds before the page appears
  • The 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 time

2Fix

Use a browser profile without extensions for development and turn Disable Cache off.

# dev tools > Network > untick Disable cache

3Verify

Reload the page twice; the second load should be clearly faster.

# compare the load time in the Network tab

Confirmed by vite.dev

Did this fix it?

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 --profile

2Fix

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-transform

Confirmed by vite.dev

Did this fix it?

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 | head

2Fix

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 transform

Confirmed by vite.dev

Did this fix it?

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 transform

2Fix

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 dev

Confirmed by vite.dev

Did this fix it?

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 fix

Next step

Want this handled for good?

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