Skip to content

fix(functions,emulators): loadTriggers() with top level await #8394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed bug where functions packaged as ESM doesn't load on emulator for some versions of Node.js 22. (#8394)
2 changes: 1 addition & 1 deletion src/deploy/functions/runtimes/node/triggerParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/functionsEmulatorRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
rawBody: Buffer;
}

let functionModule: any;

Check warning on line 26 in src/emulator/functionsEmulatorRuntime.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
let FUNCTION_TARGET_NAME: string;
let FUNCTION_SIGNATURE: string;
let FUNCTION_DEBUG_MODE: string;
Expand All @@ -48,7 +48,7 @@
return new Promise((res, rej) => {
try {
res(require(require.resolve(moduleName, opts))); // eslint-disable-line @typescript-eslint/no-var-requires
} catch (e: any) {

Check warning on line 51 in src/emulator/functionsEmulatorRuntime.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
rej(e);
}
});
Expand All @@ -58,7 +58,7 @@
return new Promise((res, rej) => {
try {
res(require.resolve(moduleName, opts));
} catch (e: any) {

Check warning on line 61 in src/emulator/functionsEmulatorRuntime.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
rej(e);
}
});
Expand Down Expand Up @@ -105,22 +105,22 @@
/**
* Gets a property from the original object.
*/
static getOriginal(target: any, key: string): any {

Check warning on line 108 in src/emulator/functionsEmulatorRuntime.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 108 in src/emulator/functionsEmulatorRuntime.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
const value = target[key];

Check warning on line 109 in src/emulator/functionsEmulatorRuntime.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access [key] on an `any` value

Check warning on line 109 in src/emulator/functionsEmulatorRuntime.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

if (!Proxied.isExists(value)) {
return undefined;
} else if (Proxied.isConstructor(value) || typeof value !== "function") {
return value;
} else {
return value.bind(target);

Check warning on line 116 in src/emulator/functionsEmulatorRuntime.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value

Check warning on line 116 in src/emulator/functionsEmulatorRuntime.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .bind on an `any` value
}
}

/**
* Run the original target.
*/
static applyOriginal(target: any, thisArg: any, argArray: any[]): any {

Check warning on line 123 in src/emulator/functionsEmulatorRuntime.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
return target.apply(thisArg, argArray);
}

Expand Down Expand Up @@ -909,7 +909,7 @@
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;
Expand Down
Loading