Deploying backend shows 404 in prod

While running packages/api in dev, it works and i used vercel link and ran the packages/api on localhost:4000 using vercel.json to give it vercel environment. But when i hosted it on vercel it shows 404 and i cant access any route. i think something is wrong with vercel.json but its still running perfectly in vercel cli.

It should run like vercel cli but the route still says 404

{
“version”: 2,
“builds”: [
{
“src”: “dist/index.js”,
“use”: “@vercel/node”,
“config”: { “includeFiles”: [“../../packages/**”] }
}
],
“routes”: [
{
“src”: “/api/trpc(?:/.)?",
“dest”: “dist/index.js”,
“headers”: {
“Access-Control-Allow-Origin”: "
”,
“Access-Control-Allow-Methods”: “GET, POST, OPTIONS”,
“Access-Control-Allow-Headers”: “Content-Type, Authorization”,
“Access-Control-Allow-Credentials”: “true”
}
}
],
“env”: {
“NODE_ENV”: “production”
}
}
this is the current vercel.json, am i missing something

There’s another community post with 404 debugging tips that might be helpful. Please give these solutions a try and let us know how it goes.

A human should be around soon to offer more advice. But you can also get helpful information quickly by asking v0.

Hey, Rohit! Welcome to the Vercel Community. Nice to see you here :smile:

Looking at your setup, there are a few potential issues with your vercel.json configuration that could cause the 404 errors in production.

  1. Could you make sure your dist/index.js file actually exists after the build? Vercel might not be finding your built files in the expected location.

  2. Your route pattern /api/trpc(?:/.*)? might be too restrictive. Try simplifying it:

{ "routes": [ { "src": "/api/(.*)", "dest": "dist/index.js" } ] }

  1. Add a build script to ensure your TypeScript/source files are compiled:

{ "version": 2, "buildCommand": "npm run build", "builds": [ { "src": "dist/index.js", "use": "@vercel/node" } ], "routes": [ { "src": "/api/(.*)", "dest": "dist/index.js" } ] }

Try these changes and check your build logs in the Vercel dashboard to see if there are any build errors or if the dist/index.js file is being created properly.

Let us know how you get on!

1 Like

hey pauline, i was able to solve it and im deploying the main website, thanks for the help

1 Like

Great to hear what worked for you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.