Express with Vercel can't import other files

Viewed 46

I've been experimenting with Express on Vercel and it straight up can't work when importing other files (NodeJS modules work fine though)

This is the root of my project:

.
├── app.ts
├── node_modules
├── package.json
├── package-lock.json
├── routes
└── vercel.json

2 directories, 4 files

This is the app.ts

import express from "express";

import testRouter from "./routes/route.js";
// Middlewares
const app = express();

app.use(testRouter);
app.get("/", (req, res) => res.send("Hello World"));

// connection
const port = process.env.PORT || 4000;
app.listen(port, () => console.log(`Listening to port ${port}`));

This is the ./routes/route.js

import { Router } from "express";

const router = Router();

router.get("/test", (req, res) => {
    res.send("Hello world from test route");
});

export default router;

This is my vercel.json

{
    "builds": [
        {
            "src": "./app.ts",
            "use": "@vercel/node"
        }
    ],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "app.ts"
        }
    ]
}

However, when deployed to vercel this is the error I face: enter image description here

0 Answers
Related