I'm having issues with connecting to my firestore DB from a cloud function.
I get the below error:
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: {} }
> }
The service account credentials are pointed to by the GOOGLE_APPLICATION_CREDENTIALS environment variable.
This is my functions code:
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);
})
});
... and these are my dependencies in my package.json file
"dependencies": {
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.3.0"
}
I've seen there are more people facing similar issues, they say I should upgrade to the latest version of the firebase-functions and firebase-admin, but in my case they are up to date. Ive also deleted node_modules/ and re-installed it again but the issue persists.
Any thoughts?
Have you ever set an environment variable called FIRESTORE_EMULATOR_HOST?
If that environment variable is set, the firebase admin SDK will try to connect to the emulator instead of the firestore, and if you haven't started the emulator, the Error: 14 UNAVAILABLE: No connection established will occur.
https://firebase.google.com/docs/emulator-suite/connect_firestore?hl=en
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With