node.js - GCP pub/sub-klienten misslyckas över version 4.0.0 med autentiseringsfel
Detta händer när jag försöker skapa ett ämne
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)
Exempel på kod:
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.`);
}
}
Svar #1
Som @vizsatiz nämnde i kommentaren:
Felet
TypeError: this.auth.getUniverseDomain is not a functionlöstes genom att nedgradera det till 3.7. Problemet uppstod när pub/sub-klienten användes över version 4.0.0. Som en lösning kan alla som stöter på samma problem med versionen över 4.0.0 överväga att nedgradera versionen som ett första steg.
Publicerar svaret som community wiki för att gynna gemenskapen som kan stöta på detta användningsfall i framtiden.
Känn dig fri att redigera detta svar för mer information.