I’m fairly new to Vercel and am really struggling getting an Express server using Turborepo and internal packages to work.
In order for Vercel to create the server less function I’m re-exporting my express app from /apps/api/src/index.ts
to /apps/api/api/index.ts
and then rewrite requests using { "source": "/(.*)", "destination": "/api/index.ts" }
. That caused issues on build however because for some reason Vercel couldn’t resolve the internal packages correctly. For that reason I’m now bundling everything instead and re-export /apps/api/dist/index.js
.
When manually deploying the project using vercel --prod
everything is building and working correctly, but deployments triggered by git pushes throw the following runtime error: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/apps/api/dist/index.js' imported from /var/task/apps/api/api/index.js
. Clearly there seem to be differences between manual deployments and automatically triggered ones, but I have no idea what they are and how to resolve them.
PS: manually deploying also worked before I bundled the code DESPITE throwing errors in the build log. After the change the build errors disappeared, but as said, automatically triggered deployments are throwing the runtime error.
simplified directory structure
/apps
/web
/api
/src
index.ts (importing /packages/db)
/dist
index.js
/api
index.js (re-rexporting /apps/api/dist/index.js)
/packages
/db
vercel.json
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"outputDirectory": "",
"rewrites": [
{
"source": "/(.*)",
"destination": "/api/index.js"
}
]
}