Skip to content
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

Merged
merged 3 commits into from Jul 9, 2020
Merged

Fix https://github.com/github/fetch/issues/657 #794

merged 3 commits into from Jul 9, 2020

Conversation

JakeChampion
Copy link
Owner

@JakeChampion JakeChampion commented Jul 8, 2020

Fixes #657

var global = (function(self) {
return self
// eslint-disable-next-line no-invalid-this
})(typeof self !== 'undefined' ? self : this)
Copy link

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.

Copy link

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.

Copy link
Owner Author

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)
> 

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"self is not defined" error in React after upgrading to 3.0.0
2 participants