-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
"Fetch failed" error in production mode #49578
Comments
This is likely fixed by #49638, can you verify that ( |
No, it didn't help. There is still the same error. |
Same here for 13.4.3-canary.0 , I get the following error with TypeError: fetch failed❯ pnpm build
> approuter-2@0.1.0 build /Users/ruslanmsv/Developer/Nextjs/approuter-2
> next build
warn - No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.
warn - https://tailwindcss.com/docs/content-configuration
- info Creating an optimized production build
- info Compiled successfully
- info Linting and checking validity of types
- info Collecting page data
[ ] - info Generating static pages (0/5)
SERVER RUN
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11522:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: AggregateError
at internalConnectMultiple (node:net:1103:18)
at afterConnectMultiple (node:net:1616:5)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
code: 'ECONNREFUSED',
[errors]: [ [Error], [Error] ]
}
}
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11522:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
- info Generating static pages (5/5)
> Export encountered errors on following paths:
/page: /
ELIFECYCLE Command failed with exit code 1. except that I can not start an app with Error: Cannot find module '/Users/ruslanmsv/Developer/Nextjs/approuter-2/.next/prerender-manifest.json'❯ pnpm start
> approuter-2@0.1.0 start /Users/ruslanmsv/Developer/Nextjs/approuter-2
> next start
- ready started server on 0.0.0.0:3000, url: http://localhost:3000
Error: Cannot find module '/Users/ruslanmsv/Developer/Nextjs/approuter-2/.next/prerender-manifest.json'
Require stack:
- /Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/next-server.js
- /Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/next.js
- /Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/lib/render-server.js
- /Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/jest-worker/processChild.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1082:15)
at /Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/require-hook.js:180:36
at Module._load (node:internal/modules/cjs/loader:928:27)
at Module.require (node:internal/modules/cjs/loader:1149:19)
at require (node:internal/modules/helpers:121:18)
at NextNodeServer.getPrerenderManifest (/Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/next-server.js:1928:26)
at new Server (/Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/base-server.js:164:32)
at new NextNodeServer (/Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/next-server.js:172:9)
at NextServer.createServer (/Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/next.js:171:24)
at async /Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/next.js:196:31 {
type: 'Error',
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/next-server.js',
'/Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/next.js',
'/Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/lib/render-server.js',
'/Users/ruslanmsv/Developer/Nextjs/approuter-2/node_modules/.pnpm/next@13.4.3-canary.0_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/jest-worker/processChild.js'
]
}
ELIFECYCLE Command failed with exit code 1. It seems that a problem is specific for default fetch and |
adding fixes the problem 🤯🥲 |
I added
|
@AlekseyMalakhov I found this problem, that may be related. My guess is that it works in dev, but something is not configured to work with localhost in production build and you have to substitute localhost with some production URL. and it's easy to check with some toy API like https://jsonplaceholder.typicode.com/todos/1 I still think, it's super weird, it's not building with localhost |
@Ruslanmsv |
I have this problem as well. It works locally but not in production. What's the best way to go around this? |
I've documented this as well, and reported a simple solution for the time being. Change the serverless function config, specifically where it's running from. A server from a different city should do the trick. |
I'm using 13.4.4 and is still happening |
Same, I encountered this error while building.
It works normally in dev mode, unable to access all API addresses in production mode
using 13.3.0 this is my code```typescript // Component const getItems = async () => { const res = await fetch('http://localhost:3000/api/item/latest?page=0', { next: { revalidate: 1800 } }) const items: ApiSuccessResponse = await res.json() return items.data }const Component = async () => { return (...)
|
I think this problem may be due to: The page requested a local API address during building, but this address has not been compiled yet, so there is no returned content. Sometimes, successful compilation may be due to obtaining the cache of dev mode during build When testing the compiled website, I found that the page where generateStaticParameters was written cannot be accessed, and provided an If the database operation is written in a component, the page content will no longer be cached, but some data (such as posts) do not need to be updated so frequently. And at this point, the server component that uses fetch will still return an error in production mode Error```log TypeError: fetch failed at Object.fetch (node:internal/deps/undici/undici:11457:11) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { cause: Error: connect ECONNREFUSED ::1:3000 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '::1', port: 3000 } } [Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] { digest: '2026204822' } ``` |
I solved the issue on my side by using a fetch ponyfill. I used it for tRPC and also anywhere else I was calling fetch on the BE. Worked like a charm. It's temporary fix though. |
@kaloyanBozhkov Could you share how you implemented this temporary fix? Thanks! |
Sure. Here's the tRPC fix:
Essentially I'm ensuring that any fetch calls are using For the BE I implemented the ponyfill inside my existing fetch GET/POST helper, which came in handy in this specific context. Here's an example of this as well:
|
Somebody with solution? When i try to deploy to production with docker i have same error. I am using local api in my server components with "fetch". `info Generating static pages (0/32) TypeError: fetch failed Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error |
inside app/dashboard/page.tsx i am using a async function to fetch from an api. The build keeps failing on vercel but locally it works |
Unfortunately there is almost no code shared in this issue which makes it quite hard to provide a definitive answer. But looking at the error messages it seems that a bunch of the reports are related to trying to fetch api routes / route handlers in server components / getServerSideProps / getStaticProps. You can't fetch api routes / route handlers in that way because during |
i'm curious, |
I'm experiencing the same issue, Im fetching an endpoint in my localhost server from a server component in next (Next 13.4.10), everything works like charm in my local environment. But then when I deploy it to Vercel the deployment works just fine, but then I navigate the App I get the following fetch error: URL:
I wrapped the fetch call in a Try/Catch so that the App doesn't break entirely, but no content is rendered at all, since the fetch call obviously will still fail. All my client side fetching to the same URL works like charm in Vercel so its just serverside fetching. I have read a lot of different threads on this subject, tried a bunch of things like switching from |
I am having the same issue. Works normally in localhost but when I deploy to production it crashes for some users. A refresh usually fixes the issue |
My suggestion is that the SSR component directly reads and writes the database in tsx, and the client component then uses fetch |
@abranaf I am facing the same issue! Have you found any solution? |
@timneutkens I can share the code to my portfolio website (which is not done yet) but I also run into this issue. The build is failing on the main page. To give a little bit more context: The
so my
my
Could it be that the api routes are not active while building the static pages? That it might be an order of execution thing? 🤔 Also some observations I've made:
Here is the link to the main page of my portfolio which causes the build to fail. |
Another observation I've made: setting |
Same error! on next@13.4.12 and deployment in vercel TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11457:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: Error: connect ECONNREFUSED ::1:3000
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 3000
}
}
Error occurred prerendering page "/todos". Read more: https://nextjs.org/docs/messages/prerender-error |
I added |
Encountered this issue after upgrading from
|
@jthomaschewski I have the same problem – only standalone build errors in prod. Actually, 13.4.12 works fine for me, but not 13.4.13. |
I suppose that the problem was introduced in this commit (13.4.13-canary.0): 1398de9#diff-52cd95be25b76891bc705a2b498cbd25530283792dd37f6bbd332feb4255ab1fR25 – it replaced |
Please read my earlier reply on this issue: #49578 (comment) No reproductions were shared still. Unless a reproduction is shared in follow-up comments this issue will be closed as it's not constructive to keep spending time writing these replies when it's clear no one is sharing a reproduction in the near future. @zaunermax your case is exactly the case I've mentioned multiple times in this issue, you're trying to fetch route handlers / api routes in components, you can't do that, there is no server running during static generation. Instead you can read the data directly, using the same functions you're using in the route handler / api route. |
@timneutkens here is a reprodution: https://github.com/b1rdex/next.js-fetch-error |
fyi @timneutkens - another person here who's hitting the same issue as @b1rdex + @jthomaschewski with 13.4.13 (next start fine, fetch failed in standalone + Docker - deployed to AWS). Many thanks to @b1rdex for providing the repro. In my case the failure happens immediately when the favicon is requested, so not much fancy happening. CloudWatch log included in case that's additionally helpful: ===
|
@timneutkens ah now I understand the point of confusion. I am using a BFF approach because the only thing that can be cached via static regeneration is next's |
Exactly, experiencing the same issue starting with |
Hi @timneutkens. Any movement on this? Similar to @b1rdex + @jthomaschewski, downgrading to 13.4.12 has temporarily resolved the issue, but would love to see a fix go in soon. |
### What? This PR makes it easier to use Next.js with IPv6 hostnames such as `::1` and `::`. ### How? It does so by removing rewrites from `localhost` to `127.0.0.1` introduced in #52492. It also fixes the issue where Next.js tries to fetch something like `http://::1:3000` when `--hostname` is `::1` as it is not a valid URL (browsers' `URL` class throws an error when constructed with such hosts). It also fixes `NextURL` so that it doesn't accept `http://::1:3000` but refuse `http://[::1]:3000`. It also changes `next/src/server/lib/setup-server-worker.ts` so that it uses the server's `address` method to retrieve the host instead of our provided `opts.hostname`, ensuring that no matter what `opts.hostname` is we will always get the correct one. ### Note I've verified that `next dev`, `next start` and `node .next/standalone/server.js` work with IPv6 hostnames (such as `::` and `::1`), IPv4 hostnames (such as `127.0.0.1`, `0.0.0.0`) and `localhost` - and with any of these hostnames fetching to `localhost` also works. Server Actions and middleware have no problems as well. This also removes `.next/standalone/server.js`'s logging as we now use `start-server`'s logging to avoid duplicates. `start-server`'s logging has also been updated to report the actual hostname. ![image](https://github.com/vercel/next.js/assets/75556609/cefa5f23-ff09-4cef-a055-13eea7c11d89) ![image](https://github.com/vercel/next.js/assets/75556609/619e82ce-45d9-47b7-8644-f4ad083429db) The above pictures also demonstrate using Server Actions with Next.js after this PR. ![image](https://github.com/vercel/next.js/assets/75556609/3d4166e9-f950-4390-bde9-af2547658148) Fixes #53171 Fixes #49578 Closes NEXT-1510 Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com> Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
Did #53131 fix this for everyone? It went in to release |
This comment has been minimized.
This comment has been minimized.
Feel free to open a new issue following the issue template providing a reproduction so that we can investigate. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
Data fetching (gS(S)P, getInitialProps)
Link to the code that reproduces this issue
https://github.com/AlekseyMalakhov/check-next-fetch-error2
To Reproduce
npm run dev
npm run build
– during build time you will notice a fetch error.npm run start
Describe the Bug
Fetch API request works in development mode but fails with error in production.
Here is an error
Expected Behavior
No error is expected when browser window is refreshed.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: