node-bunyan
node-bunyan copied to clipboard
Fixes for Webpack 5 browser environments
Webpack 5 no longer automatically provides polyfills for Node APIs from browser environments. (See "Automatic polyfills for native Node.js modules were removed" under the Webpack 5 release announcement.) This causes problems for Bunyan's use of Node.js-only globals like process and Buffer.
As I understand it, one solution is to do an explicit require and, if needed, configure Webpack's resolve.fallback option to specify how to resolve the required modules. (Bunyan does something similar to this for the os and fs modules.)
The other solution is to check whether the modules are available before continuing.
I opted for the second solution in this PR, to avoid introducing a dependency on the buffer module. This means that Bunyan won't directly support Buffer objects in the browser.
There are two references to process that I didn't update: process.env check and a reference to process.stderr.write. process.env is specially handled by Node.js, and process.stderr is addressed by #628.
@joshkel are we going to move this PR forward?
@mr-pinzhang As far as I know, it's ready to go. I haven't heard anything from the Bunyan team.
I've since switched to Pino; it's a largely drop-in replacement for Bunyan and works better with Webpack 5.