5

I have upload my project with node using express + typescript. This app generates a folder dist for building but when vercel deploy my app it doesn't run the command build so what I had to do for deploy my app is build locally and upload this dist folder. Here is my vercel.json

{
    "version": 2,
    "buildCommand": "yarn build",
    "devCommand": "yarn dev",
    "outputDirectory": "dist",
    "builds": [
        {
            "src": "dist/index.js",
            "use": "@vercel/node"
        }
      ],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "dist/index.js"
        }
    ]
}
Kaneki21
  • 1,323
  • 2
  • 4
  • 22

1 Answers1

-1

have you provided "build":"tsc" in script tag in package.json?

   "build":"tsc",
   "start": "node dist/server.js",

However, I haven't build my express with TS app and deployed it in vercel. You have to install typescript only once in vercel in order to run expressTS app without compiling/building it.

   vercel.json
        {
          "version": 2,
            "builds": [
              {
                "src": "./server.ts",   // server.ts is in root
                "use": "@vercel/node"
              }
            ],
            "routes": [
              {
                "src": "/.*",
                "dest": "server.ts"
              }
            ]
          }

package.json

{
  "name": "server",
  "version": "1.0.0",
  "description": "MERN App",
  "main": "server.ts",
  "scripts": {
    "start": "node server.ts",
    "server": "ts-node ./server.ts",
    "client": "cd ./ && npm start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "mongoose": "^6.7.2"
  },
  "devDependencies": {
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.14",
    "concurrently": "^7.5.0",
    "ts-node": "^10.9.1"
  }
}
Piyali
  • 162
  • 1
  • 4