firebase functions: onSchedule gen2 throw error on Emulator.
[REQUIRED] Environment info
firebase-tools: 12.4.3 node: functions: Using node@18 from host.
Platform: Windows 10
[REQUIRED] Test case
functions/index.ts
import {onSchedule} from "firebase-functions/v2/scheduler";
exports.dailyCron = onSchedule("every day 21:00", async (event) => {
> console.log('plop');
});
[REQUIRED] Steps to reproduce
Start emulators:
firebase emulators:start
this error show up: !! functions: Failed to load function definition from source: FirebaseError: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
[REQUIRED] Expected behavior
onSchedule Gen2 should be able to be used in local environement
[REQUIRED] Actual behavior
use of onSchedule throw error.
NB: I use onRequest Gen2 on the same environement and it work fine
The issue is equaly present when i setGlobalOptions:
import {setGlobalOptions} from "firebase-functions/lib/v2";
setGlobalOptions({ region: "europe-west3" });
Hi @Biokimist, thanks for reaching out and for providing code snippets. There are a few things I’d like to try out to help with the issue.
Regarding onSchedule, does changing your code to the below snippet cause any changes to the behavior or does it still raise an error?
import { onSchedule } from "firebase-functions/v2/scheduler";
export const dailyCron = onSchedule("every day 21:00", async (event) => {
console.log("plop");
});
AFAIK, setGlobalOptions is available on "firebase-functions/v2”. Could you try changing your import to:
import { setGlobalOptions } from "firebase-functions/v2";
Let us know if the issue still persists after trying the above. Also, could you share with us your firebase-debug.log file so that we can have a better understanding of what might be causing this?
Hi, thanks you for your time. Your proposal work fine.
import { onSchedule } from "firebase-functions/v2/scheduler";
import { setGlobalOptions } from "firebase-functions/v2";
setGlobalOptions({ region: "europe-west3" });
export const dailyCron = onSchedule("every day 21:00", async (event) => {
console.log("plop");
});
The issue is in the documentation at least to make it work on the emulator: https://firebase.google.com/docs/functions/schedule-functions?gen=2nd