Thursday, August 4, 2022

Firebase Functions emulator: avoid long loading delays when running fully offline (firewalled/no internet)

If you run Firebase Functions emulator in a completely isolated network (no access to internet), you may face unreasonably long delays when function code is being reloaded after a changes (possibly 70s or more).

In 11.1.0 (and possibly neighboring versions as well), this is because the function-loading/validating code path of the emulator performs an "update check" for the firebase-functions version used in the project. Here, to fetch the latest available version, it runs a npm show firebase-functions call which, in an offline environment, takes over a minute to time-out and return a cached result.

To solve this, you can patch lib/deploy/functions/runtimes/node/versioning.js from the firebase-tools installation directory (usu. {global NodeJS installation/lib dir}/node_modules/firebase-tools/) to skip the version check; just return a constant from the responsible function:

function getLatestSDKVersion() {
	return "3.21.2";
}

No comments: