Skip to content
Latchkey

Webpack 5 "BREAKING CHANGE: webpack < 5 used to include polyfills" in CI

Webpack 5 stopped automatically polyfilling Node core modules such as crypto, stream, and buffer for browser bundles. Any code that imports them now fails to resolve unless you supply a fallback yourself.

What this error means

The build fails with "Module not found: Error: Can't resolve 'crypto'" followed by a "BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default" note.

webpack
Module not found: Error: Can't resolve 'stream' in '/app/src'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by
default. This is no longer the case. Verify if you need this module and configure
a polyfill for it.

Common causes

Browser code imports a Node core module

A dependency or your code imports crypto/stream/buffer for a web target, which Webpack 5 no longer polyfills automatically.

A migration from Webpack 4 without fallbacks

Code that relied on Webpack 4 auto-polyfills breaks on 5 because resolve.fallback is now required for those modules.

How to fix it

Add explicit fallbacks for needed modules

  1. Decide whether the browser bundle truly needs the Node module.
  2. Install the polyfill package and map it in resolve.fallback.
  3. Set the fallback to false for modules you do not need.
webpack.config.js
resolve: {
  fallback: {
    crypto: require.resolve('crypto-browserify'),
    stream: require.resolve('stream-browserify'),
    fs: false,
  },
},

Remove the Node-only dependency

If the import is server-only, exclude that code path from the browser bundle so no polyfill is needed.

How to prevent it

  • Add resolve.fallback entries when migrating to Webpack 5.
  • Keep server-only code out of browser bundles.
  • Audit which Node core modules your web build really requires.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →