unfetch
unfetch copied to clipboard
ReferenceError: self is not defined (snowpack)
If I try to include this library in a project built with snowpack, I get this error:
ReferenceError: self is not defined
It is because this file uses an uninitialised global, which seems like a very bad idea:
https://github.com/developit/unfetch/blob/master/packages/isomorphic-unfetch/browser.js
Could we switch it from self
to something more standard like global
?
I've done a PR here which fixes:
https://github.com/developit/unfetch/pull/151
I mentioned this in the PR, but global
is not a standard. self
is a standard - it is defined in all browser environments (document, all worker types, worklet, etc).
Can you provide a bit more insight into why you need to run the browser entry for isomorphic-unfetch in Node? The code doesn't run there, regardless of whether it uses self
or Node's global
- it's a browser-based networking library that relies on XMLHttpRequest.
I'm going to close this because it should be fixed in isomorphic-unfetch 4.0.1 due to the addition of package exports.
With v5 of unfetch
this is still an issue. This occurs when using the polyfill in a node environment.
still occurs, 4.0.1 or 5.0.0
yes, but do you know how to solve it ?
yes, but do you know how to solve it ?
use node-fetch
You need to use node-fetch, and then provide global access.
https://github.com/node-fetch/node-fetch#providing-global-access