I'm deploying a Bun + Express application to Vercel. Locally, my Express app works perfectly with routes defined in separate files and imported into index.ts. However, on Vercel, the deployment consistently crashes with Bun process exited with exit status: 1 as soon as I import an express.Router() from an external file.
For example, if I have:
src/routes/empty-route.ts:
import { Router } from "express";
export const emptyRouter = Router();
emptyRouter.get('/', (req, res) => {
res.status(200).json({ message: 'This is an empty route.' });
});
// This line was added based on bun docs for Vercel middleware, but might be misplaced here. (https://bun.com/docs/guides/deployment/vercel)
export const config = { runtime: "nodejs" };
And in index.ts:
import express from 'express';
import { emptyRouter } from './src/routes/empty-route.js'; // This import causes the crash on Vercel
const app = express();
app.use('/empty', emptyRouter);
// ... other app setup
The Vercel deployment fails. I've noticed that the official Vercel Express-Bun boilerplate keeps all routes within index.ts, suggesting this might be a known limitation or a specific configuration is needed.
How can I properly modularize my Express routes into separate files and import them into my main index.ts for a Bun deployment on Vercel without causing a crash? Is the export const config = { runtime: "nodejs" }; line
in the router file problematic, or is there a specific vercel.json configuration required?
my current vercel.json is as suggested by vercel examples repo:
{
"bunVersion": "1.x"
}