Thanks to visit codestin.com
Credit goes to github.com

Skip to content

When external library polyfills it breaks Next.js #57242

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

Closed
1 task done
luthfib opened this issue Oct 23, 2023 · 4 comments
Closed
1 task done

When external library polyfills it breaks Next.js #57242

luthfib opened this issue Oct 23, 2023 · 4 comments
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.

Comments

@luthfib
Copy link

luthfib commented Oct 23, 2023

Link to the code that reproduces this issue

https://github.com/luthfib/auth0-nextjs-repro/tree/fetch-issue

To Reproduce

  1. Run intstructions as outlined in https://github.com/luthfib/auth0-nextjs-repro/tree/fetch-issue
  2. This will also require get env variables for auth0

Current vs. Expected behavior

This bug is linked to #56969, however I was able to fix it by doing the following:

https://github.com/luthfib/auth0-nextjs-repro/blob/fetch-issue/app/api/auth/%5Bauth0%5D/route.ts

I believe Next.js crashed before I included the following line because of this line the Next.js code...

if (!(response instanceof Response)) {

I think either Next.js needs to warn in the documentation that any library that polyfills fetch will break Next.js or the error if the library polyfills should be more clear. The library that polyfills in question is the following: https://github.com/Vermonster/fhir-kit-client/blob/3b36f30f29f5bbeac356feed0db6ce3be3eeb711/lib/http-client.js#L3.

Spent quite a bit of time with a few engineers to figure out what was causing the issue, so some kind of warning would be helpful.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6000
Binaries:
  Node: 18.11.0
  npm: 8.19.2
  Yarn: N/A
  pnpm: 8.9.2
Relevant Packages:
  next: 13.5.6
  eslint-config-next: 13.5.5
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Additional context

No response

@luthfib luthfib added the bug Issue was opened via the bug report template. label Oct 23, 2023
@icyJoseph
Copy link
Contributor

icyJoseph commented Oct 24, 2023

Is this caused because Node's Fetch native API?

So, rather, other libraries should check if native Node Fetch API is available, and skip doing polyfills?

@luthfib
Copy link
Author

luthfib commented Oct 24, 2023

Yeah, I believe so. It's technically on other libraries to check and not do polyfills. However Next.js does the following in some cases:

if (response && !(response instanceof Response)) {

Where it checks if the response is the same one it got initially made. If a library polyfills this will not be correct. Not everyone is ahead of the curve like Next.js, and some are still polyfilling (They shouldn't be), but mostly I think at the very least some documentation around this gotcha would be nice. Because this behavior which other libraries may not be aware of can cause some really unexpected behavior in Next.js. Took us a while to track down this bug, and I'd love it if others didn't have to experience it, or at the very least maybe they could figure out what was going on faster.

@nextjs-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@nextjs-bot nextjs-bot added the stale The issue has not seen recent activity. label Apr 23, 2025
@nextjs-bot
Copy link
Collaborator

This issue has been automatically closed due to two years of inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding!

@nextjs-bot nextjs-bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.
Projects
None yet
Development

No branches or pull requests

3 participants