I'm working on a Next.js 15 App Router project with a POST API route located at app/api/users/webhook/route.ts. In production (on Vercel), the build and API route work perfectly. But locally, when I run npm run build, I get this error:
TypeError: Cannot read properties of undefined (reading 'query')
at new nH (.next/server/app/api/users/webhook/route.js:40:4398)
at nJ.createSession (...)
...
Error: Failed to collect page data for /api/users/webhook
package.json
I'm using bun locally but running npm in CI and Vercel:
"scripts": {
"build": "next build",
...
}