fix: updated isNode check (#1221)#1363
fix: updated isNode check (#1221)#1363alexander-fenster merged 2 commits intoprotobufjs:masterfrom diegoblattner:patch-1
Conversation
* Fixes #1221 when used within SSR. `process` is a global variable since node [0.1.7](https://nodejs.org/api/globals.html#globals_process) and versions since [0.2.0](https://nodejs.org/api/process.html#process_process_versions).
|
Haven't checked and might be a false alarm, but referencing |
|
Thanks @dcodeIO, let me check this. This is basically why we decided to merge stuff on Fridays and let it bake for a while before we make an actual release next week :) I'll update the issue and/or send a fix if needed. |
|
So, several things here:
My personal opinion here is that it's better to fix the code for users who actually reported they have problems (in #1221), and then fix it once more if the fix actually breaks someone else's code (it definitely will, obligatory xkcd). Folks who really care about the extra 1.6K of minimized code will be able to configure their bundler to remove this shim. |
|
...but the bad thing is that it actually breaks |
|
The |
|
Perhaps with an additional safeguard there: function checkNodeGlobal(global) {
if (global && global.process) return global; // or whatever reasonably identifies node
return null;
}
// global object reference
util.global = typeof global !== "undefined" && checkNodeGlobal(global)
|| typeof window !== "undefined" && window
|| typeof self !== "undefined" && self
|| this; // eslint-disable-line no-invalid-this |
* Fixes protobufjs#1221 when used within SSR. `process` is a global variable since node [0.1.7](https://nodejs.org/api/globals.html#globals_process) and versions since [0.2.0](https://nodejs.org/api/process.html#process_process_versions). Co-authored-by: Alexander Fenster <fenster@google.com>
processis a global variable since node 0.1.7 and versions since 0.2.0.