Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
Closed
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
19 changes: 19 additions & 0 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,25 @@ export class Firestore implements firestore.Firestore {
// also set the `protocol` option for GAX fallback to force http
if (useFallback) {
settings.protocol = 'http';

// If the emulator mode is enabled, we set emulator credentials
// to prevent the gRPC-fallback client from trying to obtain
// service account credentials from the environment.
if (process.env.FIRESTORE_EMULATOR_HOST) {
const emulatorCredentials = {
access_token: 'owner',
};
const emulatorClient =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Root cause for failing tests. The emulatorClient (cached credentials) needs to specify the project ID. If not specified here and not specified in the firestore settings, then the project ID will not be available, causing request the Firestore instance to behave incorrectly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! How does the system tests obtain the project id? We can use the firestore settings and GCLOUD_PROJECT env var here, if that makes sense.

 emulatorClient.projectId = settings.projectId ?? process.env.GCLOUD_PROJECT;

WDYT?

// eslint-disable-next-line node/no-extraneous-require
new (require('google-auth-library').OAuth2Client)();
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since google-auth-library is not a direct dependency (it is a transient dependency of google-gax) We get extraneous-require lint error here. I think disabling it for this line is okay... WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we added 'google-auth-library' to nodejs-firestore dependencies, would that also resolve the issue? Or am I missing some other context?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, adding google-auth-library to package.json would resolve this, but I am not sure if that is necessary here as google-gax should pull in google-auth-library as a dependency anyway.

Reference: https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-extraneous-require.md

If a require()'s target is extraneous (it's not written in package.json), the program works in local, but will not work after dependencies are re-installed. It will cause troubles to your team/contributors. This rule disallows require() of extraneous modules.

emulatorClient.setCredentials(emulatorCredentials);
emulatorClient.projectId =
settings.projectId ?? process.env.GCLOUD_PROJECT;
const emulatorAuth = new (require('google-gax').GoogleAuth)({
authClient: emulatorClient,
});
settings.auth = emulatorAuth;
}
}

client = new module.exports.v1(settings, gax);
Expand Down