-
Notifications
You must be signed in to change notification settings - Fork 157
Description
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 viaexports.{name} = ...
- But
GrpcStatus
,v1
, andv1beta1
are only defined viaObject.defineProperty(module.exports, ...)
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
-
Create a Node project (Node 20+)
-
Set
"type": "module"
inpackage.json
-
Add the following to
index.js
:import { GrpcStatus } from '@google-cloud/firestore'; console.log(GrpcStatus);
-
Run:
node index.js