我在从云函数连接到我的firestore DB时遇到了问题。
我得到以下错误:
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/并重新安装了它,但问题仍然存在。
有什么想法吗?
发布于 2020-09-23 16:45:43
您是否设置过名为FIRESTORE_EMULATOR_HOST的环境变量
如果设置了该环境变量,则firebase admin SDK将尝试连接到仿真器,而不是连接到firestore,如果尚未启动仿真器,则会发生Error: 14 UNAVAILABLE: No connection established。https://firebase.google.com/docs/emulator-suite/connect_firestore?hl=en
https://stackoverflow.com/questions/61029992
复制相似问题