Webpack "Buffer is not defined" / "process is not defined" - ProvidePlugin
Webpack 5 no longer injects Node globals (Buffer, process, global) into the browser bundle. Code expecting them throws a ReferenceError at runtime. ProvidePlugin injects the global, paired with a browser polyfill for Buffer/process.
What this error means
The build succeeds but the app throws Uncaught ReferenceError: Buffer is not defined (or process/global) in the browser. A bundle-time smoke test or e2e check in CI surfaces it before deploy.
Uncaught ReferenceError: Buffer is not defined
at Object.<anonymous> (vendor.js:24531)
# or
Uncaught ReferenceError: process is not definedCommon causes
Node global used without injection
A dependency references Buffer/process/global expecting Webpack 4's automatic injection. Webpack 5 does not provide these, so they are undefined at runtime.
Polyfill present but global not wired
Even with buffer/process installed, the global name is not bound unless ProvidePlugin maps it, so the bare reference still throws.
How to fix it
Inject the global with ProvidePlugin
Install the polyfill and map the global so Webpack provides it where referenced.
npm install -D buffer process
// webpack.config.js
const webpack = require('webpack')
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser',
}),
],Pair with resolve.fallback if needed
- If the same module also imports
buffer/processby name, add them toresolve.fallback. - Confirm the polyfill packages (
buffer,process) are installed. - Verify in a browser/e2e check that the ReferenceError is gone.
How to prevent it
- Use
ProvidePluginto inject Node globals browser deps expect. - Install the matching polyfills (
buffer,process). - Run a browser/e2e smoke test in CI to catch runtime ReferenceErrors.