-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
[REQUIRED] Environment info
firebase-tools: 14.3.1
Using node 20.19.1 or 23.6.0
Platform: Ubuntu
Similarly to #8054, if you use a top level await in your functions definition the emulator locks up and doesnt serve functions.
[REQUIRED] Test case
functions.js
import { onRequest } from 'firebase-functions/https';
const buildFunc = async () => {
return onRequest((req, res) => {
res.send("It works!");
})
}
export const myFunc = await buildFunc()
[REQUIRED] Steps to reproduce
firebase emulators:start --inspect-functions
[REQUIRED] Expected behavior
TLAs should be supported in the emulator, they work on Live
[REQUIRED] Actual behavior
Functions emulator fails to start, when you request functions they hang.
Killing the emulator leaves java running with the emulator ports taken.
⚠ Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await. Use import() instead. To see where the top-level await comes from, use --experimental-print-required-tla.
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:393:13)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:363:47)
at loadESMFromCJS (node:internal/modules/cjs/loader:1569:24)
at Module._compile (node:internal/modules/cjs/loader:1721:5)
at Object..js (node:internal/modules/cjs/loader:1904:10)
at Module.load (node:internal/modules/cjs/loader:1473:32)
at Function._load (node:internal/modules/cjs/loader:1285:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)
at Module.require (node:internal/modules/cjs/loader:1495:12)
⚠ We were unable to load your functions code. (see above)
⚠ functions: Failed to initialize and load triggers. This shouldn't happen: require() cannot be used on an ESM graph with top-level await. Use import() instead. To see where the top-level await comes from, use --experimental-print-required-tla.
⚠ Your function was killed because it raised an unhandled error.
⬢ functions: Failed to handle request for function us-central1-myFunc
⬢ functions: Failed to start functions in /home/trullock/git/firebase-test/functions: FirebaseError: Failed to load function.
svenjacobs, bmcbarron and amiller-gh