Webpack 5 (Polyfill Buffer)

Enonic version: 7.6.0
OS: macOS Big Sur Version 11.1

Webpack 4 by default always polyfilled a few things, that were not always needed. In order to keep the bundle size as small as possible Webpack 5 no longer does this.

If you are using code that requires buffer you now have to polyfill it. The compiletime error suggestions doesn’t work. I have found that adding this to the webpack config plugins section works:

new webpack.ProvidePlugin({
    Buffer: ['buffer', 'Buffer']
})

You also have to add buffer to your development dependencies in your package.json file.

2 Likes