The bug manifests itself indeterministically--requests with redirects would fail randomly when running build or dev scripts.
For example, when running build, the stack track might look something like this:
info - Creating an optimized production build
info - Compiled successfully
info - Linting and checking validity of types
info - Collecting page data ..TypeError: fetch failed
at Object.fetch (/Users/foo/nextjs13-example/node_modules/next/dist/compiled/undici/index.js:1:26684)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async r.fetchData (/Users/foo/nextjs13-example/.next/server/chunks/710.js:965:103)
cause: TypeError: Cannot read properties of undefined (reading 'reason')
at makeAppropriateNetworkError (/Users/foo/nextjs13-example/node_modules/next/dist/compiled/undici/index.js:2:54604)
at schemeFetch (/Users/foo/nextjs13-example/node_modules/next/dist/compiled/undici/index.js:2:30000)
at /Users/foo/nextjs13-example/node_modules/next/dist/compiled/undici/index.js:2:28607
at mainFetch (/Users/foo/nextjs13-example/node_modules/next/dist/compiled/undici/index.js:2:29007)
at httpRedirectFetch (/Users/foo/nextjs13-example/node_modules/next/dist/compiled/undici/index.js:2:33708)
at httpFetch (/Users/foo/nextjs13-example/node_modules/next/dist/compiled/undici/index.js:2:32580)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async schemeFetch (/Users/foo/nextjs13-example/node_modules/next/dist/compiled/undici/index.js:2:30793)
at async /Users/foo/nextjs13-example/node_modules/next/dist/compiled/undici/index.js:2:28601
at async mainFetch (/Users/foo/nextjs13-example/node_modules/next/dist/compiled/undici/index.js:2:28426)
Expected Behavior
Fetches with redirects should work
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue
https://github.com/nodejs/undici/commit/e49b68d68d0d1c6fada5f92dc8ccb5c6d87d48f6
To Reproduce
Not a full repro, but see test in https://github.com/nodejs/undici/commit/e49b68d68d0d1c6fada5f92dc8ccb5c6d87d48f6 that shows how a redirect reproduces the bug.
Describe the Bug
In undici@5.12.0, a bug handling redirects was introduced. This bug was fixed in undici@5.14.0.
Next upgraded to undici@5.12.0 in commit https://github.com/vercel/next.js/commit/137008e6133e419ebf87111c225a45156d804511 which is affecting next@13.0.2 and above. I believe the fix is as simple as upgrading to undici@5.14.0, which I'm working on doing right now.
The bug manifests itself indeterministically--requests with redirects would fail randomly when running build or dev scripts.
For example, when running build, the stack track might look something like this:
Expected Behavior
Fetches with redirects should work
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response