Help

Cron jobs on NextJS

954 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Surex_422
4 - Data Explorer
4 - Data Explorer

Hi, I would like to know how to create a cron job with NextJS and Vercel. I tried it like I did with another API but with Airtable it fails to compile. This is the error : 

Failed to compile.

./node_modules/airtable/lib/airtable.umd.js
Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime 
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation

Import trace for requested module:
./node_modules/airtable/lib/airtable.umd.js


> Build failed because of webpack errors

Here is the code that creates the error :

export const config = {
  runtime: "edge",
};
var base = new Airtable({ apiKey: process.env.AIRTABLE_API_KEY }).base(
  "{base}"
);

const table = base("Orders");

export default async (req: NextRequest) => {
  // To set two dates to two variables
  var date1 = new Date();

  // To calculate the time difference of two dates
  var Difference_In_Date = date1.getDate() - 74;
  date1.setDate(Difference_In_Date);
  return await table
    .select({ filterByFormula: `(SEARCH('${date1.getFullYear()+"-"+date1.getMonth()+"-"+date1.getDate()}',{Order Date}))` })
    // .select({
    //   maxRecords: 1,
    //   filterByFormula: `SEARCH("12293781",{Order_Unique Number})`,
    // })
    .all(function page(objs) {
      objs.forEach(function (obj:any) {
        let firstName = obj.get("Customer_First Name");
        let email = obj.get("Customer_Email");
        if (obj.get("Order_Collected") == true) {
          ...
        }
      });
    });

Thank you for the answer in advance!

0 Replies 0