-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
safely use global #4
Comments
Why? It’s a node module. global can’t ever not exist. |
Uh-oh.
results in:
@ljharb is it better to handle the issue here or in https://github.com/es-shims/Array.prototype.find? |
This comment has been minimized.
This comment has been minimized.
@oles global is always defined in node; are you using a bundler that doesn’t define it? |
Should have noted that this happened in Firefox, where the usecase is polyfilling Array.prototype.find (and .flat). Sorry for missing this vital information, @ljharb! |
I'm using webpack, let me check my config tomorrow! |
Webpack absolutely understands global by default or it wouldn’t be able to bundle most of npm. |
Aha. I've set Though this might not be the case in the future? Thanks for the help, @ljharb! |
I doubt the global polyfill, which is a single line ( |
@ljharb - I also hit the same problem in a browser environment. Bundler is webpack with
That is, I'm using Why don't you just make |
@boris-petrov it is browser-friendly; I could certainly use https://www.npmjs.com/package/globalthis instead of relying on |
@ljharb - I don't want to argue too much because polyfilling Again, feel free to ignore my comment as it is not a big deal, but I believe that right now the behavior is not correct. Thank you for the time! |
You’re totally right that global doesn’t work in a browser - but by default, any npm package that uses global (and there are a great many) is transpiled to use window by every bundler. Using node: false is disabling that default and thus deviating from community convention. require doesn’t work in the browser either, but i don’t see you complaining about the use of require - this is a node module, and “browser friendly” for all node modules means “transpiles the way browserify does by default”. |
OK, fair enough! Thanks again! |
https://docs.npmjs.com/files/package.json#browser You can specify a separate implementation for node and browser environments - this way your package would work out of the box for both and neither includes code that is not needed. As pointed out in a comment above, webpack 5 no longer transpiles |
Webpack 5 isn’t out yet, and i still hope to convince them to restore the proper behavior of transpiling global to window. You’re right that i could duplicate the entire file just to change global to window, but since every bundler window the beginning of node has done that, it seems like a strange redundancy to force on the entire ecosystem. |
still getting this issue, can't we use globalThis instead global? |
@bhushanlaware no, can’t we use non-broken bundlers instead of broken ones? |
in the source code
i think this one better
The text was updated successfully, but these errors were encountered: