I am trying to deploy my backend to Vercel but increasing the maxDuration to 30 seconds. However, builds
does not support modifying a functions maxDuration so I attempted to use the functions
config. However, my backend is written in TypeScript with the code compiled in a dist
directory. My main route file is called index.js
inside an API folder, meaning after compilation that file is in /dist/api/index.js
. Regardless of what I do, Vercel does not recognize my function and wants it to be in an api
directory, which I can’t pull off since my compiled files are directed to the dist
directory.
My current vercel.json
file is:
{
"version": 2,
"buildCommand": "npm run build",
"installCommand": "npm install",
"builds": [
{
"src": "dist/api/index.js",
"use": "@vercel/node",
"config": {
"includeFiles": ["dist/**"]
}
}
],
"routes": [
{
"src": "/(.*)",
"dest": "dist/api/index.js"
}
]
}
Snippet of my package.json
:
{
"name": "backend",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"build": "rimraf dist && tsc",
"ts.check": "tsc --project tsconfig.json",
"start": " node ./dist/api/index.js",
"add-build": "git add dist",
"test": "nyc --reporter=html --reporter=json --reporter=text mocha dist/test --experimental-modules --timeout 10000 --exit",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate"
},
"keywords": [],
"author": "",
"license": "ISC",
"pre-commit": [
"ts.check",
"build",
"add-build"
],
A different vercel.json
file which I tried:
{
"version": 2,
"buildCommand": "npm run build",
"installCommand": "npm install",
"outputDirectory": "dist",
"functions": {
"api/index.js": {
"maxDuration": 30,
"includeFiles": "dist/**"
}
}
}
The exact error is:
The pattern "api/index.js" defined in
functionsdoesn't match any Serverless Functions inside the
api directory.