Search code examples
node.jsexpressvercel

Vercel build never ends


I'm having a problem with Vercel platform, probably because I'm not using it right.

Locally I can deploy the server without problems on port 3000. But when I want to deploy in Vercel, Build gets stuck at the express function app.listen().

Image Vercel error:
Image Vercel error

My index.js is like any other and ends with the function:

// listening the server
app.listen(app.get('port'), () => {
    console.log('Server on port ', app.get('port'));
});

I've tried everything I don't know what to do anymore, surely I have a conceptual error.


Solution

  • Vercel is for front-end (and serverless)

    Sites deployed on Vercel are mainly front-end. (React, Vue, and everything else that becomes HTML/CSS/JS).

    By the looks of it you're trying to run a back-end application (Node.js) on Vercel, which it isn't designed for. (Instead, consider using a VPS or a managed environment/app platform)

    Vercel also supports serverless functions, which you could use to run your back-end with. These are essentially one-off functions that are run on a new server instance every time a request comes in.

    All that considered, if you're indeed trying to build and deploy a front-end app...

    A wild guess

    Your build script is calling your node application. You might have something like the following in your package.json:

    "scripts": {
      "build": "tsc && node src"
    }
    

    This would run tsc first, then start the application by running the built files.

    However, you don't want to start your application as part of the build process -- instead, make the build command only build your app, nothing more.

    Then, on Vercel, go to your project's settings page and make sure that command is used to Build your app.

    My app doesn't need to be built (I've already got plain HTML/CSS/JS files)

    If your app doesn't need to be built at all, go to your project's settings page and remove the "Build Command" entirely.