我正在使用 Firebase 模拟器。直到 4 小时前,一切正常。但是现在,我模拟的云函数触发了以下错误:
> 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)
Run Code Online (Sandbox Code Playgroud)
我清楚地发现了问题:每次我执行 Firestore 请求时都会出现这个问题。
例如,这是整个函数的减法:
return new Promise((resolve, reject) => {
db.doc(`users/${userId}`).update({ dbUpdated: new Date() })
.then(() => {
resolve();
})
.catch(e => reject(e));
});
Run Code Online (Sandbox Code Playgroud)
如果我将其替换为:
return Promise.resolve();
Run Code Online (Sandbox Code Playgroud)
我不再有错误了。但显然我不再有预期的行为......
我做了一个很大的重构(我安装了airbnb风格的eslint,所以我不得不修改相当多的文件),所以我可能做错了什么。但是经过几个小时的研究,我还没有发现什么可以证明这个错误:(
我在下面给你我的代码的相关摘录。我的实际代码要长得多,但我单独测试了这个提取物:它重现了错误(如果我像前面显示的那样替换“markUserUpdated”函数,它就会消失。)
最后但并非最不重要的一点是,我确认 Firestore 模拟器工作正常:应用程序运行良好,可以使用来自模拟器的数据。
谢谢你的帮助!
index.js :
const functions = require('firebase-functions');
const { db } …Run Code Online (Sandbox Code Playgroud) javascript firebase firebase-tools google-cloud-functions google-cloud-firestore