fix: only access Node.js globals if available #3501
Merged
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.
The
process
object is only available in Node.js and Node.js-like environments (e.g. webpack).By introducing this simple change, the code can run in a browser environment without requiring polyfilling Node.js APIs such as the following:
globalThis
is part of the ECMA 2020 specification and is supported on any relevant platform.The eslint config specifies ecma version 2020 but it seems like the
globalThis
is not automatically provided. I added thees2020
env. (eslint/eslint#15199 (comment))Closes #2409