Question about next.js and fetch polyfill
See original GitHub issueHello!
I have a dependency in my application that specifically relies on window.fetch being replaced with the whatwg-fetch polyfill. whatwg-fetch is a transitive dependency, so it should be ending up in my build, but it looks like next.js is replacing it with something else.
From reading the docs it seems like next provides it’s own fetch polyfill? Does that sound right, or am I totally off track here?
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Question about next.js and fetch polyfill · Issue #10509 - GitHub
Hello! I have a dependency in my application that specifically relies on window.fetch being replaced with the whatwg-fetch polyfill.
Read more >Supported Browsers and Features - Next.js
js polyfills fetch () in the Node.js environment. You can use fetch() in your server code (such as getStaticProps / getServerSideProps ) without...
Read more >How to fetch() from public folder in NextJS? - Stack Overflow
I have web worker within which I need to fetch image that is located in NextJS public folder in order to convert it...
Read more >NextJS / React SSR: 21 Universal Data Fetching Patterns ...
To answer this question, let's have a look at the challenges involved with universal data fetching in NextJS. But first, what actually is ......
Read more >Axios vs. fetch(): Which is best for making HTTP requests?
Without question, some developers prefer Axios over built-in APIs for ... To begin using the fetch() polyfill, install it via npm command ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’m not saying the optimization is not good! I’m just saying that Pretender explicitly added it as a dependency, and even explicitly imports from it here: https://github.com/pretenderjs/pretender/blob/master/src/index.ts#L2
It’s not that Mirage requires a specific implementation of
window.fetch, it’s that Pretender literally depends on the actualwhatwg-fetchdependency. The developers added it and imported it because they wanted specific behavior from that specific package – which should be a completely valid thing for anyone to do, for any package + for any reason!I do not think you should change the defaults, I’m just saying, swapping out a dependency like this is extra/magical behavior with a lot of assumptions baked into it. Doing it is fine, but not providing an escape hatch seems completely wrong to me. And I would bet good money that many users will not deoptimize their apps unintentionally… the escape hatch should be an advanced configuration option that folks in situations like ours opt-into in very specific situations.
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.