vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.98k stars 26.98k forks source link

Fetch wrapper for App directory throws an exception in node 16 when cloning a response #48873

Closed andrewliden closed 1 hour ago

andrewliden commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 16.20.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.3.2-canary.7
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue

https://github.com/andrewliden/nextjs-appdir-node16-bug-reproduction/tree/appdir-template

To Reproduce

Make sure your Node version is 16.20. Start the reproduction template with next dev. Open the homepage in your browser. The homepage will perform a request with fetch and attempt to clone the response. You will get a "Found invalid object in transferList" error.

Describe the Bug

Cloning a response in node 16.20 throws an exception. This can cause a wide range of issues, and is generally unexpected. The documentation currently states that the minimum supported version of node is 16.8.

Expected Behavior

Cloning a response should not throw an exception in Node 16, unless Node 16 is no longer intended to be supported.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

icyJoseph commented 1 year ago

Reproduction repository is not correct?

andrewliden commented 1 year ago

Reproduction repository is not correct?

Are you referring to the fact that the template was created with npx create-next-app -e reproduction-template instead of npx create-next-app -e reproduction-template-app-dir?

If so, I'm sorry, I just didn't notice that the app directory template was separate when I started making the bug reproduction repository. The repository does use the app directory, though. I could update the repository if needed, just let me know.

andrewliden commented 1 year ago

Reproduction repository is not correct?

I went ahead and created a new branch that's using the app directory template. I edited the issue to link to that branch, as well. Hopefully that helps.

icyJoseph commented 1 year ago

Does node-fetch support response cloning? In Node 16 there's no fetch on the Node runtime, so IIRC, Next.js polyfills it with node-fetch.

andrewliden commented 1 year ago

Does node-fetch support response cloning? In Node 16 there's no fetch on the Node runtime, so IIRC, Next.js polyfills it with node-fetch.

It seems so. https://github.com/node-fetch/node-fetch/blob/main/src/response.js#L89

andrewliden commented 1 year ago

It might be worth noting that I first ran into this problem because a project I was working on was crashing unexpectedly due to responses attempting to call .clone(). None of the code in that project actually called .clone(), so it would seem it might be used under the hood somewhere. I had some trouble reproducing that behavior, though, so I just reproduced the exception with .clone() since that seems to be what was causing my problems anyways.

jabedzaman commented 1 year ago

My solution to this was keep your dev server running while deploying it on vercel or ceating a local build... 💀

andrewliden commented 1 year ago

My solution to this was keep your dev server running while deploying it on vercel or ceating a local build... 💀

For me it was resolved when I updated to Node v18, so I just updated the container to use that. The documentation claimed that Node v16.8 and later is supposed to be supported though.

samcx commented 1 hour ago

The current minimal Node.js support version is v18.17 → https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration#nodejs-version.

Since v16 is no longer supported, I will be closing this issue!