Vite build warns that some chunks are larger than 500 kB
(!) Some chunks are larger than 500 KiB after minification.Short answer
This is a warning, not a failed build. Vite flags any output chunk above build.chunkSizeWarningLimit, whose default is 500 (kB). Fix it by loading heavy code on demand with dynamic import() so it becomes its own chunk, or raise the limit when you have decided the size is acceptable.
Fix it fast
1Find out which cause you have
Look at the build output table to see which chunk is big, then check what that chunk contains.
npx vite build2Match what you see, then jump to its fix
What does the error look like?
(!) Some chunks are larger than 500 KiB after minification.Some chunks are larger than 500 kB after minification
Cause 1 of 2
Heavy code is imported statically, so it lands in the main chunk
1Check
Charts, editors, PDF or map libraries and whole route trees that are imported at the top of a file are part of the first download.
grep -rn "^import" src/main.* src/router* | head -302Fix
Load the heavy part with dynamic import(). Vite turns each dynamic import into its own chunk and adds a preload step, and it extracts the CSS of an async chunk into a separate file.
// route-level split
const routes = [
{ path: '/reports', component: () => import('./views/Reports.vue') },
]
// library split
const { default: Chart } = await import('chart.js/auto')3Verify
Run the build again: the large chunk is smaller and new chunk files appear.
npx vite buildConfirmed by vite.dev
Cause 2 of 2
The size is expected and only the warning limit is in the way
1Check
The default of build.chunkSizeWarningLimit is 500, in kB. A chunk above it only triggers the warning.
grep -n "chunkSizeWarningLimit" vite.config.*2Fix
Raise the limit in vite.config to the size you accept, so real regressions still show up later.
// vite.config.js
import { defineConfig } from 'vite'
export default defineConfig({
build: {
chunkSizeWarningLimit: 800,
},
})3Verify
The warning is gone for chunks below 800 kB.
npx vite buildConfirmed by vite.dev
How do I stop it coming back?
- Lazy-load routes and rarely used screens with dynamic import().
- Import single functions from a library, not the whole package.
- Check the build table in CI so a sudden jump in chunk size is noticed.
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