GCP pub/sub client is failing above version 4.0.0 with auth error
Asked Answered
L

1

7

This happens when I try to create a topic

   TypeError: this.auth.getUniverseDomain is not a function
        at GrpcClient.createStub (/Users/<...>/node_modules/google-gax/src/grpc.ts:418:48)
        at processTicksAndRejections (node:internal/process/task_queues:95:5)

Sample Code:

pubSubClient = new PubSub({
      "projectId": "project_name"
    });

initTopic = async () => {
    // Creates a new topic if it does not exist
    const [topics] = await this.pubSubClient.getTopics()
    RootLogger.info("topic names: " + topics.join(","))
    const topicExists = topics.some(topic => topic.name.endsWith(this.topicName));

    if (topicExists) {
      RootLogger.info(`Topic ${this.topicName} already exists.`);
    } else {
      await this.pubSubClient.createTopic(this.topicName);
      RootLogger.info(`Topic ${this.topicName} created.`);
    }
  }
Laconism answered 11/2, 2024 at 9:59 Comment(5)
Same problem, started about a week ago without any meaningful code changes.Mouton
I have fixed it by downgrading to 3.7Laconism
The issue is opened on github in the google auth package. link 1 link 2 link 3Civil
The third one was raised by me :PLaconism
Hi @Laconism , I have just posted your comment as a community workaround answer to help anyone who is facing the same issue. You can also consider creating a ticket in the issue tracker.Barytone
B
2

As @vizsatiz mentioned in the comment:

The error TypeError: this.auth.getUniverseDomain is not a function was solved by downgrading it to 3.7. The problem occurred when using the pub/sub client above version 4.0.0. As a workaround, anyone facing the same issue with the version above 4.0.0 can consider downgrading the version as a first step.

Posting the answer as community wiki for the benefit of the community that might encounter this use case in the future.

Feel free to edit this answer for additional information.

Barytone answered 11/2, 2024 at 9:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.