diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb2d..1da268b8f25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +- Fixed bug where functions packaged as ESM doesn't load on emulator for some versions of Node.js 22. (#8394) diff --git a/src/deploy/functions/runtimes/node/triggerParser.js b/src/deploy/functions/runtimes/node/triggerParser.js index d05b72f842f..6773049d0bf 100644 --- a/src/deploy/functions/runtimes/node/triggerParser.js +++ b/src/deploy/functions/runtimes/node/triggerParser.js @@ -21,7 +21,7 @@ async function loadModule(packageDir) { try { return require(packageDir); } catch (e) { - if (e.code === "ERR_REQUIRE_ESM") { + if (e.code === "ERR_REQUIRE_ESM" && e.code !== "ERR_REQUIRE_ASYNC_MODULE") { const modulePath = require.resolve(packageDir); // Resolve module path to file:// URL. Required for windows support. const moduleURL = url.pathToFileURL(modulePath).href; diff --git a/src/emulator/functionsEmulatorRuntime.ts b/src/emulator/functionsEmulatorRuntime.ts index 8720c3b08ab..bfb1732a8cc 100644 --- a/src/emulator/functionsEmulatorRuntime.ts +++ b/src/emulator/functionsEmulatorRuntime.ts @@ -909,7 +909,7 @@ async function loadTriggers(): Promise { try { triggerModule = require(process.cwd()); } catch (err: any) { - if (err.code !== "ERR_REQUIRE_ESM") { + if (err.code !== "ERR_REQUIRE_ESM" && err.code !== "ERR_REQUIRE_ASYNC_MODULE") { // Try to run diagnostics to see what could've gone wrong before rethrowing the error. await moduleResolutionDetective(err); throw err;