Closed RMacfarlane closed 4 years ago
should just use globalThis
and if it isn't supported one should just do
self.globalThis = self
window.globalThis = window
global.globalThis = global
in top of their script runtime
this is intended for use with a bundler which should handle this sort of thing, are you having problems somewhere
I'm using webpack and targeting webworker
. The bundler does not do any sort of shim for global, in a webworker the only way to access the global object is self
.
Webpack 100% provides a global shim, and will provide it once to be shared by all your code, have you either turned this off? Or has web pack maybe decided to break stuff by turning it off by default?
On Thu, Sep 3, 2020, 11:16 AM Rachel Macfarlane notifications@github.com wrote:
I'm using webpack and targeting webworker. The bundler does not do any sort of shim for global, in a webworker the only way to access the global object is self.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/crypto-browserify/randombytes/pull/24#issuecomment-686562358, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAITRHZYX7DPC5KMY5HWIRDSD6XLFANCNFSM4O4YOTLA .
Perhaps unintentionally.
IMO, I shouldn't have to fiddle with my bundler to get this code to run in a browser context, it should be able to do so without outside intervention.
I know for a fact that this has worked with webpack in the past. So if it's not working out of the box anymore that could be a webpack change that will effect a lot of other libraries. I can look into it more but not until after labor day.
On Thu, Sep 3, 2020, 2:57 PM Rachel Macfarlane notifications@github.com wrote:
Perhaps unintentionally.
IMO, I shouldn't have to fiddle with my bundler to get this code to run in a browser context, it should be able to do so without outside intervention.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/crypto-browserify/randombytes/pull/24#issuecomment-686695634, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAITRH2VWKQXDGLCLKHUVUDSD7RJHANCNFSM4O4YOTLA .
Thanks!
Here's the webpack config I'm using, I may just be doing something stupid: https://github.com/microsoft/vscode/blob/616afa93e2da5a5a92b14863bab8b339b977edc4/extensions/microsoft-authentication/extension-browser.webpack.config.js
That being said, I think it's pretty easy to misconfigure webpack, and it would be helpful to others if there wasn't direct global
usage that needs to be shimmed
what version of webpack is this ?
4.43.0
I think you turned it off here
If you don't intend to accept fixes for https://github.com/crypto-browserify/randombytes/issues/22, please close it, then.
Fixes https://github.com/crypto-browserify/randombytes/issues/22