-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix https://github.com/github/fetch/issues/657 #794
Conversation
var global = (function(self) { | ||
return self | ||
// eslint-disable-next-line no-invalid-this | ||
})(typeof self !== 'undefined' ? self : this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add some fallback such as an empty object?
I know this whatwg-fetch is intended to be used only in browser, however, it gives many conveniences by just "importing it" and not using it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To illustrate more, I'm suggesting to make importing 'whatwg-fetch' in nodejs environment works, while blocking the usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works in NodeJS correctly because the global this
works in NodeJS.
Here the output of running it in NodeJS
❯ node -v
v14.4.0
❯ node
Welcome to Node.js v14.4.0.
Type ".help" for more information.
> var global = (function(self) {
... return self
... // eslint-disable-next-line no-invalid-this
... })(typeof self !== 'undefined' ? self : this)
undefined
> global
<ref *1> Object [global] {
global: [Circular *1],
clearInterval: [Function: clearInterval],
clearTimeout: [Function: clearTimeout],
setInterval: [Function: setInterval],
setTimeout: [Function: setTimeout] {
[Symbol(nodejs.util.promisify.custom)]: [Function (anonymous)]
},
queueMicrotask: [Function: queueMicrotask],
clearImmediate: [Function: clearImmediate],
setImmediate: [Function: setImmediate] {
[Symbol(nodejs.util.promisify.custom)]: [Function (anonymous)]
}
}
>
(To exit, press ^C again or ^D or type .exit)
>
Fixes #657