What build command should I configure in Vercel settings when my package.json has npm run build script?

I’m working with a Node.js TypeScript project and trying to deploy it on Vercel. My build works fine locally but seems to fail during deployment.

My package.json scripts:

{
  "scripts": {
    "dev": "nodemon --exec npx tsx server/index.ts",
    "build": "tsc && tsc-alias"
  }
}

My tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "CommonJS",
    "moduleResolution": "node",
    "outDir": "build",
    "rootDir": "server",
    "strict": true,
    "esModuleInterop": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["server/*"]
    }
  },
  "include": ["server/**/*"]
}

My vercel.json:

{
  "version": 2,
  "builds": [{
    "src": "build/index.js",
    "use": "@vercel/node"
  }],
  "routes": [{
    "src": "/(.*)",
    "dest": "build/index.js"
  }]
}

When I run the build locally, everything compiles correctly and creates the build folder. However, after deploying to Vercel, I notice the compiled files are missing from the deployment output. It looks like TypeScript compilation isn’t happening during the Vercel build process. What should I set as the build command in Vercel’s project settings to make this work properly?

Your build command looks fine - Vercel should pick up npm run build automatically. The real problem is your vercel.json treats this like a traditional server instead of using Vercel’s serverless setup.

I hit the same issue migrating a TypeScript API to Vercel. Fixed it by ditching the custom vercel.json completely and restructuring for Vercel’s conventions. Instead of compiling to a build folder, I moved route handlers to /api and let Vercel handle TypeScript compilation.

Your current setup could work if you make sure build output gets included in deployment, but you’re fighting Vercel’s design and adding complexity with tsc-alias.

I’d refactor your endpoints as individual serverless functions in /api. Kills the build config headaches and works perfectly with Vercel without custom commands or configs.

Just hit this exact issue last month. Your build command should be npm run build in Vercel settings, but there’s a timing problem with your setup.

Vercel runs the build fine, but your vercel.json is looking for build/index.js before TypeScript actually compiles during deployment. The build creates the files, but routing expects them to exist already.

I’d restructure and use Vercel’s API routes pattern instead. Move your server logic to the api directory and let Vercel handle compilation automatically. Way cleaner than dealing with custom builds and tsc-alias headaches.

If you’re stuck with your current structure, make sure your build command runs the full compilation chain and double-check that your output directory matches what vercel.json expects. The timing between build and file availability can break deployments even when everything works locally.

The build command isn’t your real issue. Vercel should pick up npm run build from package.json automatically.

Your actual problem? You’re trying to deploy a backend Node.js app to Vercel, which is built for frontends and serverless functions. Your full server setup won’t play nice with Vercel’s platform.

I’ve hit this wall before - deployment headaches are the worst. Rather than wrestling with platform limits and build configs, I just automate everything.

Here’s what I do: set up automated workflows that build, test, and deploy to the right platform for each project type. Node.js backends get deployed to proper server environments instead of getting shoehorned into frontend platforms.

The automation handles TypeScript compilation, path resolution, and deployment - no manual config needed. No more debugging build commands or platform fights.

This has saved me tons of deployment troubleshooting time. Set it up once and you’re done.

Check out Latenode for deployment automation: https://latenode.com

the build command isn’t your problem - vercel auto-detects npm run build anyway. your vercel.json is looking for build/index.js but typescript compilation probably isn’t finishing before vercel tries to access it. delete the vercel.json file first and test that. vercel’s defaults handle typescript pretty well now.