Trouble configuring function path on vercel.json

Cannot configure function using vercel.json. Current vercel configuration:

{
  "build": {
    "env": {
      "NEXT_PUBLIC_CONFIG_FILE": "next.config.mjs"
    }
  },
  "crons": [
    {
      "path": "/api/cron/backup",
      "schedule": "0 23 * * *"
    }
  ],
  "functions": {
    "api/cron/backup": {
      "memory": 3009,
      "maxDuration": 300
    }
  }
}


The cron works and executes the function every day. Adding the functions configuration breaks the build with this error:
image

I know the function exists because it executes every day and is recognized on the deploy’s “functions” tab:

I have also tried slightly different paths including /api/cron/backup and api/cron/backup/*

Hi, is it a Next.js app? Can you share the folder structure?

1 Like

Hi @giovanioliani, could you try function name with the file extension, for example:

"functions": {
    "api/cron/backup.js": {
      "memory": 3009,
      "maxDuration": 300
    }
  }

To learn more about function configurations, see function keys.

I hope this helps. If it doesn’t, please include additional information such as framework, folder structure, etc, as Swarnava requested previously.

Hi. Yes, it is a Next.js app. The folder structure has an “app” directory at the root, then /api/cron/backup/route.ts.

Hi, I’ve tried it but it doesn’t match the file unfortunately. The folder structure is shared in my previous comment.

  "functions": {
    "app/api/cron/backup/route.ts": {
      "memory": 3008,
      "maxDuration": 300
    }

or

  "functions": {
    "app/api/cron/backup/*.ts": {
      "memory": 3008,
      "maxDuration": 300
    }

or

  "functions": {
    "app/api/cron/backup/*.*": {
      "memory": 3008,
      "maxDuration": 300
    }

Should work I believe

1 Like

Unfortunately none of those work. I get these errors:

Hi @giovanioliani, can you use the format that @swarnava suggested above because it should include “app” in the path which the image above doesn’t show.

I just tried replicating your project:

And it worked fine for me. Here’s the output:

1 Like

Thank you for pointing that out @anshumanb . I had tried so many times I became numb to the details. Using “app/api/cron/backup/route.ts” worked for me. You can close this if you want to.

2 Likes

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