Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
unfetch/polyfill doesn’t work in webpack 2 #31
Comments
|
that is why i saying for years to not use single dot |
|
Ah good catch - @sapegin @tunnckoCore, are we good just to change |
|
That should be the same, so probably to |
|
Hm - but if someone is using this via webpack 2 the entrypoint would actually be I just re-read the story here and I actually think we're fine with if (!window.fetch) {
window.fetch = (require('unfetch').default || require('unfetch'));
}Seem reasonable? alternatively: if (!window.fetch) {
window.fetch = (function(a){ return a.default || a })(require('unfetch'));
} |
|
Yeah, that should work too. Will send a PR. |
|
What do you guys do about |
|
Nevermind. I think my comment is unrelated because I'm talking about server bundling with |
|
@enapupe indeed - for that case, are you able to use |
|
Since I don't actually want to polyfill it on node, I ended up doing my own
version of `polyfill.js`:
https://github.com/CheesecakeLabs/fetch/blob/unfetch/src/utils/polyfill.js
It does nothing if window isn't defined.
This works for me because on node I mock fetch with webpack define plugin
at a global level, not as a window prop. And I don't really run `fetch`
calls on ssr as it doesn't really waits for them to complete before
returning the template code. So I just `noop` it.
Thanks for your suggestion anyway.
|
When I do:
I see this error in Safari 10:
Because
fetchis actually a ES module wrapper:I suppose it’s because you have
require('.')inpolyfll.jsand webpack 2 resolves it toindex.es.js. So this code works for me:I’d be happy to submit a PR but not sure what would be the right fix for this.