question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about next.js and fetch polyfill

See original GitHub issue

Hello!

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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
samselikoffcommented, Feb 13, 2020

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 actual whatwg-fetch dependency. 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.

0reactions
balazsorban44commented, Jan 30, 2022

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.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found