Vercel doesn't generate serverless function when i'm pushing commit, but does when i manually deploy

As I said in the title, there’s a weird behavior and maybe i’m in the wrong since it’s my first day on Vercel…

I’m deploying a fastify serverless function and managed to do so using vercel’s CLI (ie vercel deploy --prod) - this part works great!

When pushing to my main branch and hoping the function is also deployed, no function is deployed and i’m facing a 404 error.

Here’s my vercel.json if it’s any help:

{
    "version": 2,
    "builds": [
        {
            "src": "dist/serverless.js",
            "use": "@vercel/node"
        }
    ],
    "rewrites": [
        {
            "source": "/(.*)",
            "destination": "dist/serverless.js"
        }
    ]
}

This is usually an issue with your git provider config for example if your commits are being registered under an account different from what the Vercel account is setup under no automated deploy will happen (there are some exceptions to this but this is a common cause of the issue if you have multiple git accounts on one device.

2 Likes

I understand that but I’m already integrated with Github via Vercel, using the same mail:

And yet when looking at the deployment history you can see Vercel distinguishing both “accounts”:


For example, the second to last doesn’t work (FaresKi doesn’t deploy however fareski does, even though the former is already integrated…)

Up? Still haven’t heard back from a Vercel staff member :slight_smile:

I have a few ideas, though I don’t know enough about your project and deployment workflow to be certain which is most likely in your case.

It could be that dist is not working for your serverless function because it’s seen as the output directory. You could get it working if you change the output directory in Build Settings if that’s the problem.

The typical directory for serverless functions is /api, which has the added benefit of automatic runtime detection (i.e. you wouldn’t need the builds section at all). You might get it working by putting the serverless function code in an /api directory at the root of the project. You can read more about that here: Using the Node.js Runtime with Serverless Functions

If Ignored Build Step is set for the project, that could be preventing Git deployments.

The other possibility is that the /dist/serverless.js path doesn’t exist on the git deployment due to some difference in deployment steps or possibly some git ignored files that are present in your local repo but missing from remote. A .env file is a common example, but it could be anything related to the build.

If you can share a minimal reproducible example and tell us the exact steps you use to deploy successfully with the CLI, that would give us more clues.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.