Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Webpack 5 browser environments #664

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

joshkel
Copy link

@joshkel joshkel commented Mar 22, 2021

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 added 2 commits March 22, 2021 09:55
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][1].)
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][2] to specify how
to resolve the `require`d 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][3] 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 trentm#628.

[1]: https://webpack.js.org/blog/2020-10-10-webpack-5-release/
[2]: https://stackoverflow.com/q/64557638/25507
[3]: https://www.npmjs.com/package/buffer
@mr-pinzhang
Copy link

@joshkel are we going to move this PR forward?

@joshkel
Copy link
Author

joshkel commented Sep 15, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants