Next.js (or standard) scheduled functions cannot deploy to production

Hi,

I’m having problems deploying my app to the production site (staging seems to work just fine) since I introduced a test scheduled api route to my next.js application:

import { NextApiRequest, NextApiResponse } from "next";

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
  // Do something scheduled
  console.log("Scheduled API called", req);

  return res.status(200).send("OK");
};

export default handler;

export const config = {
  type: "experimental-scheduled",
  schedule: "0 */10 * ? * *", //"5 3 * * *" // Every day at 03:05
};

The error I am getting is all the way at the end of the deploy step (see log in attachment):

Could not create scheduled functions: Fields missing or invalid: functions[0].cron

On my staging branch deploys this works just fine (allthough the scheduled api route is not called as is stated in the documentation).

I also got the same error when using seperate (regular) scheduled functions, so I don’t think it is next.js related.

Netlify site name: plutus-pos.netlify.app

Hey @Plutus,

Do you think you can share your repo (or create a minimal reproduction apart from the above code), to help us check this? Feel free to share it with Hrishikesh-K on GitHub.

Hi @hrishikesh, thank you for getting back to me!

I cannot share my original repo, but I created a public test repository and it has the same error:

https://github.com/Nickman87/netlify-test

The only changes to a default setup are:

  • Code is inside of a subdirectory api
  • The new appDir is activated
  • Added a scheduled function inside pages/api/schedules

I did not change anything else about the next.js default application.

Thank you for the reproduction. I can confirm this happens, and have filed an issue for the devs to look at. We will follow-up as we have more info.

1 Like

Hey @Plutus,

Sorry about the delay. The issue was because we only support Cron based on this specification: cron package - github.com/robfig/cron/v3 - Go Packages

Your Cron has more fields than supported.

1 Like