Skip to content

ERR_REQUIRE_ASYNC_MODULE when deploying with Node.js v22.12.0 #8054

Closed
firebase/firebase-functions
#1651
@gustavopch

Description

@gustavopch

[REQUIRED] Environment info

firebase-tools: 13.28.0

Platform: GitHub Actions • Ubuntu 24.04.1 LTS (list of included software) • Node.js v22.12.0

[REQUIRED] Test case

While I don't have an MCVE at the moment, I believe the cause may be this specific line, which seems to be the only require() call in firebase-functions:
https://github.com/firebase/firebase-functions/blob/9ed934d3dc4c2c257ac1968a65f6913c73ca779f/src/runtime/loader.ts#L49.

[REQUIRED] Steps to reproduce

Try to deploy anything to Firebase Functions using Node.js v22.12.0 with "type": "module" in package.json. I was able to deploy just yesterday via GitHub Actions (it ran with Node.js v22.11.0). In fact, Node.js v22.12.0's changelog lists this "notable change": require(esm) is now enabled by default, which seems related to the error shown in the logs below.

[REQUIRED] Expected behavior

Should not crash.

[REQUIRED] Actual behavior

Run yarn firebase deploy \
  yarn firebase deploy \
    --message "$(date +%Y-%m-%d)-$(git rev-parse --short HEAD)" \
    --force
  shell: /usr/bin/bash -e {0}
  env:
    FIREBASE_TOKEN: ***
    FORCE_COLOR: 3
    npm_config_cache: /home/runner/.npm
yarn run v1.22.22
$ /home/runner/work/<omitted>/node_modules/.bin/firebase deploy --message 2024-12-11-b8e1fafe --force
(node:1930) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
⚠  Authenticating with `FIREBASE_TOKEN` is deprecated and will be removed in a future major version of `firebase-tools`. Instead, use a service account key with `GOOGLE_APPLICATION_CREDENTIALS`: https://cloud.google.com/docs/authentication/getting-started
(node:1930) [DEP0044] DeprecationWarning: The `util.isArray` API is deprecated. Please use `Array.isArray()` instead.

=== Deploying to '<omitted>'...

i  deploying functions
i  functions: preparing codebase default for deployment
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
i  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
✔  functions: required API cloudbuild.googleapis.com is enabled
⚠  functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory.
i  functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8460

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:392:13)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:329:47)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1414:24)
    at Module._compile (node:internal/modules/cjs/loader:1547:5)
    at Object..js (node:internal/modules/cjs/loader:1677:16)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:219:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12) {
  code: 'ERR_REQUIRE_ASYNC_MODULE'
}


Error: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions