Next.js Discord

Discord Forum

Help finding an Unhandled Promise Rejection

Unanswered
Cesky Terrier posted this in #help-forum
Open in Discord
Cesky TerrierOP
Hey, pulling my hair out the last few days. It seems that I'm getting some random internal 500 errors and I'm struggling to find the root cause. Here's an example:

Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: fetch failed","reason":{"errorType":"TypeError","errorMessage":"fetch failed","cause":{"errorType":"ConnectTimeoutError","errorMessage":"Connect Timeout Error","code":"UND_ERR_CONNECT_TIMEOUT","name":"ConnectTimeoutError","message":"Connect Timeout Error","stack":["ConnectTimeoutError: Connect Timeout Error","    at onConnectTimeout (node:internal/deps/undici/undici:7492:28)","    at node:internal/deps/undici/undici:7448:50","    at Immediate._onImmediate (node:internal/deps/undici/undici:7480:13)","    at process.processImmediate (node:internal/timers:478:21)","    at process.topLevelDomainCallback (node:domain:160:15)","    at process.callbackTrampoline (node:internal/async_hooks:128:24)"]},"stack":["TypeError: fetch failed","    at node:internal/deps/undici/undici:12345:11","    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)","    at async globalThis.fetch (/var/task/.next/server/chunks/6543.js:1:36497)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: fetch failed","    at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)","    at process.emit (node:events:530:35)","    at process.emit (node:domain:488:12)","    at emit (node:internal/process/promises:150:20)","    at processPromiseRejections (node:internal/process/promises:284:27)","    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]}
Error: Runtime exited with error: exit status 128 (Unhandled Promise Rejection)


But I'm having trouble tracking down the exact fetch that's failing. Sadly this is all the error Vercel gives (sometimes it just also gives a Unknown application error occurred.

I can see it's referencing .next/server/chunks/6543.js:1:36497 so I'm wondering if there's anyway to look at that file and somehow figure out where the problem is? To us, this appears to be a new random thing that we just can't quite figure out where it's coming from.

Is there anyway with this error message to help me figure it out?

5 Replies

@Cesky Terrier Hey, pulling my hair out the last few days. It seems that I'm getting some random internal 500 errors and I'm struggling to find the root cause. Here's an example: Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: fetch failed","reason":{"errorType":"TypeError","errorMessage":"fetch failed","cause":{"errorType":"ConnectTimeoutError","errorMessage":"Connect Timeout Error","code":"UND_ERR_CONNECT_TIMEOUT","name":"ConnectTimeoutError","message":"Connect Timeout Error","stack":["ConnectTimeoutError: Connect Timeout Error"," at onConnectTimeout (node:internal/deps/undici/undici:7492:28)"," at node:internal/deps/undici/undici:7448:50"," at Immediate._onImmediate (node:internal/deps/undici/undici:7480:13)"," at process.processImmediate (node:internal/timers:478:21)"," at process.topLevelDomainCallback (node:domain:160:15)"," at process.callbackTrampoline (node:internal/async_hooks:128:24)"]},"stack":["TypeError: fetch failed"," at node:internal/deps/undici/undici:12345:11"," at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"," at async globalThis.fetch (/var/task/.next/server/chunks/6543.js:1:36497)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: fetch failed"," at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)"," at process.emit (node:events:530:35)"," at process.emit (node:domain:488:12)"," at emit (node:internal/process/promises:150:20)"," at processPromiseRejections (node:internal/process/promises:284:27)"," at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]} Error: Runtime exited with error: exit status 128 (Unhandled Promise Rejection) But I'm having trouble tracking down the exact fetch that's failing. Sadly this is all the error Vercel gives (sometimes it just also gives a `Unknown application error occurred`. I can see it's referencing `.next/server/chunks/6543.js:1:36497` so I'm wondering if there's anyway to look at that file and somehow figure out where the problem is? To us, this appears to be a new random thing that we just can't quite figure out where it's coming from. Is there anyway with this error message to help me figure it out?
does it only happen in prod? have you tried building and runing on locally?
try enable sourcemap too
// next.config.js
module.exports = {
  productionBrowserSourceMaps: true,
}
@Ray does it only happen in prod? have you tried building and runing on locally? try enable sourcemap too ts // next.config.js module.exports = { productionBrowserSourceMaps: true, }
Cesky TerrierOP
Hey only happens on prod, can't seem to replicate with a local build. Will check source map
Cesky TerrierOP
Just enabled the productionBrowserSourceMaps and am awaiting a new error in Vercel, thanks for your help this far ❤️
@Ray does it only happen in prod? have you tried building and runing on locally? try enable sourcemap too ts // next.config.js module.exports = { productionBrowserSourceMaps: true, }
Cesky TerrierOP
Hey, so it sadly didn't give much more insight. We've literally nearly stripped out all calls and cannot find the culprit. The fact it can randomly happen no matter what page you're on is the biggest concern so with that we started from the root layout up, and cannot seem to find the problem 😦