Open ghost opened 7 years ago
The sources expect a node.js environment, while the distribution files wrap the sources through browserify and uglifyjs, where the latter defines an outer iife including the global
var (see).
If you are building your own distribution files form the sources using something else than browserify, respective configuration might be required. In this case, though, there should probably be an additional check added testing for the existence of global
for compatibility with other bundlers than browserify (see also).
util.isNode = Boolean(typeof global !== "undefined" && global && global.process && global.process.versions && global.process.versions.node);
typeof global !== "undefined"
is exactly what needed.
To overcome this issue, right now we add this to index.html:
<script>
global = {}
</script>
Right! This is a bigger scandal than Trump's RussiaGate, but it turns out our Webpack config had
target: 'node',
rather than
target: 'web',
(a copy-paste mistake)
The latter just works out of the box and there's no need for the global = {}
hack above.
So it works with Webpack.
Not sure whether this ticket should be closed or not. Adding typeof global !== "undefined"
serves right an isNode
predicate.
But with nothing breaking, why fix? Also, not having typeof global !== "undefined"
could hint that some outer configuration is wrong.
I'm going to leave this for you guys to decide.
Close at will.
protobuf.js version: 6.8.0
We run this:
(Same thing with
-w commongjs
, by the way)Then import it like so in a JSX:
Using babel, webpack emits the client code, using this babel configuration:
But when running in the browser, we get:
Which is that line in
minimal.js
:Now that makes sense, since we are in browser environment and not node.
I just wonder if we're doing something wrong, or should
minimal.js
not assume node environment?