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.
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
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
- Replace
process.env.Xreads with bundler-provided env (e.g. DefinePlugin orimport.meta.env). - Avoid
Buffer/globalin browser bundles; use Web APIs instead. - Add
resolve.fallbackonly for the specific core modules a dependency truly needs.
How to prevent it
- Audit for
process/Buffer/globalusage before upgrading to webpack 5. - Inject env via DefinePlugin rather than expecting an ambient
process. - Add only the specific
resolve.fallbackpolyfills your deps require.