Next.js Discord

Discord Forum

`request.method` causing EDGE_FUNCTION_INVOCATION_FAILED when deployed

Answered
MattIPv4 posted this in #help-forum
Open in Discord
:Wave_Doggo: Running into this error only when the app is deployed to Vercel, not locally. The stack doesn't seem to point to anything of substance making it rather hard to debug.

[GET] /api/stream/ambassadors reason=EDGE_FUNCTION_INVOCATION_FAILED, status=500, user_error=true
TypeError: Illegal invocation: function called with incorrect `this` reference. See https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors for details.
    at (../../node_modules/.pnpm/next@15.1.4_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/esm/server/web/spec-extension/adapters/reflect.js:3:0)
    at (../../node_modules/.pnpm/next@15.1.4_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/esm/server/route-modules/app-route/module.js:525:37)
    at (src/app/api/stream/ambassadors/route.ts:84:14)
    at (../../node_modules/.pnpm/next@15.1.4_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/esm/server/route-modules/app-route/module.js:308:48)
    at (../../node_modules/.pnpm/next@15.1.4_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/esm/server/route-modules/app-route/module.js:450:21)
    at (../../node_modules/.pnpm/next@15.1.4_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/esm/server/lib/trace/tracer.js:135:0)
    at (../../node_modules/.pnpm/next@15.1.4_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7052)
    at (../../node_modules/.pnpm/next@15.1.4_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:480)
    at (../../node_modules/.pnpm/next@15.1.4_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18079)


It seems to point to https://github.com/alveusgg/alveusgg/blob/e2c5442d9eb4d7b8cd21925415d1f089105b2478/apps/website/src/app/api/stream/ambassadors/route.ts#L84 ?
Answered by joulev
definitely a nextjs bug here, i suggest you report the bug
View full answer

7 Replies

Southern yellowjacket
deployed to Vercel
huh but how come you got a Cloudflare invocation error there then?
Edge funtion runtime, which is just Cf workers under the hood
Southern yellowjacket
ah right
Fun to see that implementation detail leak through though for sure
Switching the runtime to nodejs makes it work, no code changes beyond the runtime line :Thonk:
definitely a nextjs bug here, i suggest you report the bug
Answer
To close the loop a bit more, this is definitely somewhat a bug when request.method is access in an edge function that is also marked as force-static. It probably shouldn't throw that very ungraceful error. Removing force-static allows it to work, which somewhat makes sense -- the way we had this written with a method check inside the GET handler didn't even make sense.