Nobody plans a bundler upgrade for fun. Mine came from a list of software composition analysis (SCA) findings: vulnerable transitive dependencies that couldn’t be patched while the project was pinned to Webpack 4 and its loader ecosystem. Out of 35 findings on that project, we closed 33. The Webpack 5 migration unlocked a large share of them.
What actually breaks
1. Node.js core polyfills are gone. Webpack 4 silently bundled browser shims for buffer, crypto, stream, path and friends. Webpack 5 doesn’t. Builds fail with “Module not found”. You can either:
// webpack.config.js
resolve: {
fallback: {
buffer: require.resolve('buffer/'),
stream: require.resolve('stream-browserify'),
crypto: false, // better: remove the browser dependency on it
},
},
Treat each fallback as a question: why is browser code importing a Node module? Often the answer is a library you can replace or drop.
2. Asset loaders change. file-loader, url-loader and raw-loader are replaced by built-in asset modules:
{ test: /\.(png|svg|jpg)$/i, type: 'asset' } // inline small, emit large
3. Plugins and loaders need majors too. Upgrade them together and read each changelog. This is where most of the time goes.
How I’d sequence it
- Upgrade the build tooling only: no app code changes, no “while I’m here” refactors.
- Get a green build, then compare bundle output (size per chunk) against the old build.
- Run the full regression suite plus a visual smoke test of key pages.
- Re-run the SCA scan and confirm the findings are actually gone.
- Ship behind a normal release. Keep the diff easy to revert.
Bonus wins
- Persistent caching (
cache: { type: 'filesystem' }) makes rebuilds noticeably faster. - Better long-term caching with deterministic chunk and module IDs.
- A dependency tree that can keep receiving security patches.
Security work often feels like chores. Here it bought a faster build and a codebase that’s cheaper to keep patched.