【发布时间】:2020-04-04 14:59:25
【问题描述】:
我在从云功能连接到 Firestore 数据库时遇到问题。
我收到以下错误:
i functions: Beginning execution of "test"
> Error: 14 UNAVAILABLE: No connection established
> at Object.callErrorFromStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
> at Object.onReceiveStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/client.js:174:52)
> at Object.onReceiveStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:340:141)
> at Object.onReceiveStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:303:181)
> at Http2CallStream.outputStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:114:27)
> at Http2CallStream.maybeOutputStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:153:22)
> at Http2CallStream.endCall (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:140:18)
> at Http2CallStream.cancelWithStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:430:14)
> at ChannelImplementation.tryPick (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/channel.js:214:32)
> at Object.updateState (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/channel.js:82:26) {
> code: 14,
> details: 'No connection established',
> metadata: Metadata { internalRepr: Map {}, options: {} }
> }
GOOGLE_APPLICATION_CREDENTIALS 环境变量指向服务帐户凭据。
这是我的函数代码:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
let db = admin.firestore();
exports.test = functions.https.onRequest((req, res) => {
db.collection("users").doc("test").set({
'name': 'Michael'
}).then(ref => {
res.send(ref.id);
})
.catch(err => {
console.error(err)
res.status(500).send(err);
})
});
...这些是我在package.json 文件中的依赖项
"dependencies": {
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.3.0"
}
我看到有更多人面临类似问题,他们说我应该升级到最新版本的 firebase-functions 和 firebase-admin,但就我而言,它们是最新的。我还删除了node_modules/ 并重新安装了它,但问题仍然存在。
有什么想法吗?
【问题讨论】:
-
您不需要 googleapis 依赖项。尝试删除它。
-
另请注意,
set()不会生成快照。调用snap.data()将失败。 googleapis.dev/nodejs/firestore/latest/… -
编辑了我的示例代码。我需要 googleapis 来做其他事情,但仍然尝试将其删除,但仍然无法正常工作。
标签: node.js firebase google-cloud-firestore google-cloud-functions