Fixes for Webpack 5 browser environments #664
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andBuffer
.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 therequire
d modules. (Bunyan does something similar to this for theos
andfs
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 toprocess.stderr.write
.process.env
is specially handled by Node.js, andprocess.stderr
is addressed by #628.