admin管理员组文章数量:1279123
I am using Firebase Emulators. Until 4 hours ago, everything was working fine. But now, my emulated cloud functions trigger the following error:
> Error with Backup TypeError: Channel credentials must be a ChannelCredentials object
> at new ChannelImplementation (/Users/pitouli/Documents/GIT/my-app/functions/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/channel.js:67:13)
> at new Client (/Users/pitouli/Documents/GIT/my-app/functions/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/client.js:57:36)
> at new ServiceClientImpl (/Users/pitouli/Documents/GIT/my-app/functions/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/make-client.js:49:5)
> at GrpcClient.createStub (/Users/pitouli/Documents/GIT/my-app/functions/node_modules/google-gax/build/src/grpc.js:220:22)
I clearly identified the problem: it appears every time I'm doing a Firestore request.
For example, this is a substract of the whole function:
return new Promise((resolve, reject) => {
db.doc(`users/${userId}`).update({ dbUpdated: new Date() })
.then(() => {
resolve();
})
.catch(e => reject(e));
});
If I replace it by:
return Promise.resolve();
I do not have the error anymore. But obviously I do not have the expected behavior anymore...
I made a big refactor (I installed eslint with airbnb style, so I had to modify quite a lot of files), so I probably made something wrong. But after few hours of research, I haven't found what would justify this error :(
I give you below a relevant extract of my code. My real code is by far longer, but I tested this extract alone: it reproduces the error (and if I replace the "markUserUpdated" functions as shown previously, then it disappears.)
Last but not least, I confirm that the Firestore emulator is working fine: the app is running well with datas from the emulator.
Thanks for your help!
index.js
:
const functions = require('firebase-functions');
const { db } = require('./admin');
const DEBUG = true;
function markUserUpdated(userId) {
return new Promise((resolve, reject) => {
db.doc(`users/${userId}`).update({ dbUpdated: new Date() })
.then(() => {
if (DEBUG) console.log('User successfully marked Updated', userId);
resolve();
})
.catch(e => reject(e));
});
}
exports.writeContact = functions.firestore
.document('users/{userId}/contacts/{contactId}')
.onWrite((doc, context) => {
const { userId } = context.params;
return markUserUpdated(userId);
});
admin.js
:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const serviceAccount = require('../serviceAccountKey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: '',
storageBucket: 'my-app.appspot',
});
const db = admin.firestore();
const { FieldValue } = admin.firestore;
const { Timestamp } = admin.firestore;
const storage = admin.storage();
module.exports = {
db, storage, FieldValue, Timestamp, functions,
};
Edit: the code is proceeded by Babel (I do not know if it could have an influence)
I am using Firebase Emulators. Until 4 hours ago, everything was working fine. But now, my emulated cloud functions trigger the following error:
> Error with Backup TypeError: Channel credentials must be a ChannelCredentials object
> at new ChannelImplementation (/Users/pitouli/Documents/GIT/my-app/functions/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/channel.js:67:13)
> at new Client (/Users/pitouli/Documents/GIT/my-app/functions/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/client.js:57:36)
> at new ServiceClientImpl (/Users/pitouli/Documents/GIT/my-app/functions/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/make-client.js:49:5)
> at GrpcClient.createStub (/Users/pitouli/Documents/GIT/my-app/functions/node_modules/google-gax/build/src/grpc.js:220:22)
I clearly identified the problem: it appears every time I'm doing a Firestore request.
For example, this is a substract of the whole function:
return new Promise((resolve, reject) => {
db.doc(`users/${userId}`).update({ dbUpdated: new Date() })
.then(() => {
resolve();
})
.catch(e => reject(e));
});
If I replace it by:
return Promise.resolve();
I do not have the error anymore. But obviously I do not have the expected behavior anymore...
I made a big refactor (I installed eslint with airbnb style, so I had to modify quite a lot of files), so I probably made something wrong. But after few hours of research, I haven't found what would justify this error :(
I give you below a relevant extract of my code. My real code is by far longer, but I tested this extract alone: it reproduces the error (and if I replace the "markUserUpdated" functions as shown previously, then it disappears.)
Last but not least, I confirm that the Firestore emulator is working fine: the app is running well with datas from the emulator.
Thanks for your help!
index.js
:
const functions = require('firebase-functions');
const { db } = require('./admin');
const DEBUG = true;
function markUserUpdated(userId) {
return new Promise((resolve, reject) => {
db.doc(`users/${userId}`).update({ dbUpdated: new Date() })
.then(() => {
if (DEBUG) console.log('User successfully marked Updated', userId);
resolve();
})
.catch(e => reject(e));
});
}
exports.writeContact = functions.firestore
.document('users/{userId}/contacts/{contactId}')
.onWrite((doc, context) => {
const { userId } = context.params;
return markUserUpdated(userId);
});
admin.js
:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const serviceAccount = require('../serviceAccountKey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://my-app.firebaseio.',
storageBucket: 'my-app.appspot.',
});
const db = admin.firestore();
const { FieldValue } = admin.firestore;
const { Timestamp } = admin.firestore;
const storage = admin.storage();
module.exports = {
db, storage, FieldValue, Timestamp, functions,
};
Edit: the code is proceeded by Babel (I do not know if it could have an influence)
Share Improve this question edited May 5, 2020 at 13:12 Pitouli asked May 5, 2020 at 3:20 PitouliPitouli 4291 gold badge5 silver badges14 bronze badges 5- If you think this is a bug with the emulator, then file an issue on GitHub. github./firebase/firebase-tools – Doug Stevenson Commented May 5, 2020 at 3:22
- It can be a bug, but it's even more probable that I am the cause of the problem :( I reverted all the firebase dependencies updates I made today, and the problem persists. Do you know how is created the "Channel credentials"? – Pitouli Commented May 5, 2020 at 3:35
-
1
Hi @Pitouli this documentation here indicates how you need to connect your emulator and how the
ChannelCredentials
is needed and configurated. Could you please take a look at it and see if it helps you? – gso_gabriel Commented May 5, 2020 at 13:34 - Thank you @gso_gabriel! Reinstalling all the node_modules made the trick, but it will definitely be helpful if a similar issue happens! – Pitouli Commented May 5, 2020 at 15:51
- 1 Deleting the node_modules did not work for me. Anyone have the same issue? – ryanulit Commented May 9, 2020 at 3:20
3 Answers
Reset to default 9The issue is due to the specific version of the google-gax package.
I was able to fix the problem by the following step.
$ npm i -D google-gax
Deleting the functions/node_modules folder and reinstalling them all has solved the issue.
I'll e back to edit this post if I reproduce the action that made the app broke.
I had to:
- remove node_modules
- update dependencies
- reinstall
as follows
cd functions
rm -rf node_modules
npm install -g npm-check-updates
ncu -u
npm install
版权声明:本文标题:javascript - Firebase Emulator Error: Channel credentials must be a ChannelCredentials object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741245906a2364869.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论