How to fix NestJS deployment error to the Vercel?

Viewed 2555

enter image description here

this is the now.json

{
  "version": 2,
  "name": "nestjs-now",
  "builds": [
    {
      "src": "dist/main.js",
      "use": "@now/node"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "dist/main.js"
    }
  ]
}

I'm not sure what's the reason and how to fix. I just followed the vercel tutorial to deploy my nestjs backend project, but don't works. It inclues GraphQL APIs and Rest APIs together as well as socket.io server.

2 Answers

Why it doesn't work?

Serverless Functions on Vercel (at the moment) do not accept a build step for the code of the function. For that reason, any backend framework that needs a "build step" to generate a server, will not work.

What Vercel is best for?

Frontend deployments and Serverless Functions as helpers. Full-blown APIs should be deployed elsewhere. You can check the following resources:

What are my options?

I recommend that you use Heroku or Digital Ocean as alternatives.


Update 2021-11-11

Now you can deploy any framework with SSR, API routes, and Edge Functions (soon) to Vercel. Just make sure you are following the File System API specification.

You can read the introduction section for more information. Remember that Vercel is a platform optimized for frontend deployments.

the problem is that VERCEL looks for the DIST folder as soon as it starts the BUILD process

What you can do is remove the DIST folder from the .gitignore this way it will resolve the 404

after that, whenever you make a new deploy it is necessary to force deploy without cache to compile your dist againe

Related