Skip to content
Latchkey

webpack 5 "process is not defined" - Fix Removed Node Polyfills

webpack 4 auto-polyfilled Node globals like process and Buffer for the browser. webpack 5 removed that, so code (or a dependency) referencing process now throws at runtime, and the build no longer auto-injects the shim.

What this error means

After moving to webpack 5, the app throws Uncaught ReferenceError: process is not defined (or Buffer/global), or the build errors that a Node core module needs a fallback. webpack 4 had no such issue.

webpack
Module not found: Error: Can't resolve 'process/browser'
# or at runtime:
Uncaught ReferenceError: process is not defined
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.

Common causes

webpack 5 dropped automatic Node polyfills

Code or a dependency reads process.env, Buffer, etc., expecting the browser polyfill webpack 4 injected automatically. webpack 5 ships none by default.

No ProvidePlugin/DefinePlugin shim configured

Without explicitly defining process.env or providing process/Buffer, the reference is undefined in the bundle.

How to fix it

Provide the polyfill and define process.env

Inject process/Buffer with ProvidePlugin and supply env values with DefinePlugin.

webpack.config.js
// webpack.config.js
const webpack = require('webpack')
plugins: [
  new webpack.ProvidePlugin({ process: 'process/browser', Buffer: ['buffer', 'Buffer'] }),
  new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') }),
],
resolve: { fallback: { process: require.resolve('process/browser'), buffer: require.resolve('buffer') } },

Stop relying on Node globals in browser code

  1. Replace process.env.X reads with bundler-provided env (e.g. DefinePlugin or import.meta.env).
  2. Avoid Buffer/global in browser bundles; use Web APIs instead.
  3. Add resolve.fallback only for the specific core modules a dependency truly needs.

How to prevent it

  • Audit for process/Buffer/global usage before upgrading to webpack 5.
  • Inject env via DefinePlugin rather than expecting an ambient process.
  • Add only the specific resolve.fallback polyfills your deps require.

Related guides

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