Skip to content

ESM named import of GrpcStatus causes runtime errorΒ #2371

@kaisermann

Description

@kaisermann

Description

I'm migrating a backend service from CommonJS to ESM. It uses firebase-admin, which in turn depends on @google-cloud/firestore.

After resolving all static import issues, the application starts , but immediately crashes with this runtime error:

import { GrpcStatus, FieldValue, DocumentReference, Timestamp, GeoPoint } from '@google-cloud/firestore';
         ^^^^^^^^^^
SyntaxError: Named export 'GrpcStatus' not found. The requested module '@google-cloud/firestore' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@google-cloud/firestore';
const { GrpcStatus, FieldValue, DocumentReference, Timestamp, GeoPoint } = pkg;

Interestingly, all other named exports work as expected, except for GrpcStatus (and also v1, v1beta1).


Investigation

Upon inspecting the published code, I noticed that:

  • Most named exports (e.g., FieldValue, Timestamp) are defined via exports.{name} = ...
  • But GrpcStatus, v1, and v1beta1 are only defined via Object.defineProperty(module.exports, ...)

Screenshot

As far as I understand, when Node.js attempts to statically analyze a CommonJS module (with __esModule), it only picks up exports defined via exports.{name} = .... So the absence of exports.GrpcStatus = ... prevents it from being recognized as a valid named export.

Manually adding the following line resolves the issue:

exports.v1beta1 = exports.v1 = exports.GrpcStatus = void 0;

That makes GrpcStatus importable in ESM as expected.


Question

The JSDoc in the source indicates GrpcStatus is marked as private, but the TypeScript type definitions expose it publicly.

So: Is GrpcStatus considered a public export or not?

If it is public, the current export mechanism is broken for ESM users.


Environment

  • OS: macOS 15.5
  • Node.js: 22.14.0
  • npm: 10.2.5
  • @google-cloud/firestore: 7.11.1

Steps to Reproduce

Minimal repro: StackBlitz

  1. Create a Node project (Node 20+)

  2. Set "type": "module" in package.json

  3. Add the following to index.js:

    import { GrpcStatus } from '@google-cloud/firestore';
    console.log(GrpcStatus);
  4. Run: node index.js

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/nodejs-firestore API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions