Hey everyone,
I’m hitting a wall deploying a monorepo project (React frontend + Node/Express/TS backend) and hoping someone might have seen this before.
Locally, everything works fine. On Vercel, my frontend loads okay, but any request to my API routes (like POST /api/user/login or GET /api/health) fails. Instead of hitting the Node.js function, they seem to get caught by the frontend’s fallback route. POST requests get a 405 Method Not Allowed (with HTML content), and GET requests just redirect to the frontend app.
The weirdest part is absolutely no logs show up in the Vercel dashboard for the backend function when I try to hit these API endpoints. It’s like the requests never even reach the function code.
Setup:
My vercel.json defines separate builds for frontend (@vercel/static-build) and backend (@vercel/node). The backend build config includes includeFiles for backend/dist/** and sets the entrypoint to backend/dist/index.js. The routes look standard: /api/(.*) points to /backend/dist/index.js, followed by handle: filesystem, static rewrites, and the final SPA fallback to /frontend/index.html.
My backend Express app (backend/src/index.ts) sets up routes synchronously before the export default app. I even added logging middleware right at the start, but those logs never appear for API requests on Vercel.
Troubleshooting:
Confirmed backend code does build successfully into backend/dist/index.js during Vercel deployment (had to add a workaround to the frontend’s build script in its package.json to force the backend build, as Vercel was ignoring the backend buildCommand).
Tried various vercel.json route dest paths (/backend/dist/index.js, /backend/package.json).
Tried tweaking the backend build config (entrypoint, includeFiles path relativity, buildCommand).
Ensured root package.json doesn’t set “type”: “module”.
Confirmed Vercel project root directory is blank.
Cleared Vercel build cache.
Tested with curl (confirms 405/redirect with HTML response).
Has anyone run into this specific issue where Vercel routes for a Node function seems to fail silently, hitting the SPA fallback with zero function logs generated? It feels like something between the Vercel router and the function invocation isn’t connecting, even though the build artifact seems correct. Any ideas what settings I might be missing?
Thanks in advance!