Description:
I’m encountering a persistent “404 Not Found” error when deploying my full-stack application on Vercel. My project uses a Vite frontend and a Node.js/Express backend, structured as a monorepo. I’ve followed the Vercel documentation and numerous online resources, but I’m still unable to resolve the issue.
Current vs. Expected Behavior:
- Current Behavior: After deployment, I receive a “404 Not Found” error when accessing the deployed URL. The backend API routes also do not seem to be accessible.
- Expected Behavior: The frontend should be served correctly, and the backend API routes should be accessible.
Code, Configuration, and Steps to Reproduce:
-
Project Structure:
seo-content-gen-bot/ <-- Root directory ├── backend/ │ └── content-generator-server.js (Express server) │ └── package.json (Backend package.json) ├── frontend/ │ ├── src/ │ │ └── ... │ ├── index.html │ ├── package.json (Frontend package.json - main field REMOVED) | └── vite.config.js ├── dist/ <-- Created by "npm run build" in frontend │ ├── index.html │ └── ... ├── vercel.json └── ...
-
vite.config.js
(frontend):import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; export default defineConfig({ plugins: [react()], build: { outDir: '../dist' } });
-
vercel.json
(root):{ "version": 2, "builds": [ { "src": "backend/content-generator-server.js", "use": "@vercel/node" }, { "src": "dist", "use": "@vercel/static" } ], "routes": [ { "src": "/api/(.*)", "dest": "backend/content-generator-server.js" }, { "src": "/(.*)", "dest": "dist/index.html" } ] }
-
Steps:
npm run build
is executed in thefrontend
directory, successfully creating thedist
folder in the project root.- All changes (including the
dist
folder andvercel.json
) are committed and pushed to GitHub. - The project is deployed on Vercel.
- The “Root Directory” setting in Vercel project settings is set to BLANK.
Project Information:
- Project URL: [Your Vercel deployment URL (if you have one, even if it’s 404ing)]
- Framework: Vite (Frontend), Node.js/Express (Backend)
- Environment: Vercel Production
- Project Settings:
- Root Directory: BLANK
- Build Command (Frontend):
npm run build
- Output Directory (Frontend):
dist
- Install Command (Frontend):
npm install
- Git Repository: [Your GitHub repository URL]
Additional Information:
- I have verified that the
dist
folder is correctly created in the root of my project after runningnpm run build
. - I have double-checked the paths in my
vercel.json
file. - I have cleared the Vercel build cache multiple times.
- I have tried creating a new Vercel project and re-importing the repository.
- I have removed the
"main"
field from my frontend’spackage.json
.
I’m at a loss as to what could be causing this issue. Any help would be greatly appreciated!
Thanks in advance.