当我尝试创建主题时会发生这种情况
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)
示例代码:
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.`);
}
}
正如@vizsatiz 在评论中提到的:
错误
已通过降级至3.7解决。使用4.0.0以上版本的pub/sub客户端时出现该问题。作为解决方法,任何在 4.0.0 以上版本中遇到相同问题的人都可以考虑首先降级版本。TypeError: this.auth.getUniverseDomain is not a function
将答案发布为
community wiki
,以造福于将来可能遇到此用例的社区。
请随意编辑此答案以获取更多信息。