firebase-tools: 7.0.2
平台: Oracle Linux Server 7.6,节点10.15
用“ firebase-admin”:“ ^ 8.2.0”,“ firebase-functions”:“ ^ 3.0.2”模拟https函数
使用firebase函数运行任何https
没有错误(firebase-tools 7.0.0不会引发错误)
已发送功能请求。
firebase > ⚠ Error: The incoming JSON object does not contain a client_email field
at JWT.fromJSON (/riderequest/functions/node_modules/google-auth-library/build/src/auth/jwtclient.js:165:19)
at GoogleAuth.fromJSON (/riderequest/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:294:16)
at GoogleAuth.getClient (/riderequest/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:476:52)
at GrpcClient._getCredentials (/riderequest/functions/node_modules/google-gax/build/src/grpc.js:107:40)
at GrpcClient.createStub (/riderequest/functions/node_modules/google-gax/build/src/grpc.js:223:34)
at new FirestoreClient (/riderequest/functions/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:128:39)
at ClientPool.Firestore._clientPool.pool_1.ClientPool [as clientFactory] (/riderequest/functions/node_modules/@google-cloud/firestore/build/src/index.js:315:26)
at ClientPool.acquire (/riderequest/functions/node_modules/@google-cloud/firestore/build/src/pool.js:61:35)
at ClientPool.run (/riderequest/functions/node_modules/@google-cloud/firestore/build/src/pool.js:114:29)
at Firestore.request (/riderequest/functions/node_modules/@google-cloud/firestore/build/src/index.js:957:33)
⚠ Your function was killed because it raised an unhandled error.
相关的stackoverflow帖子: https :
@noelmansour谢谢,所以好像是造成7.0.1
和7.0.2
之间的某种情况,我将看看所做的更改。
从7.0.2开始我也遇到了这个问题
刚刚升级到7.0.2,也看到了这一点。 检查了我的帐户凭据,并且出现了client_email
字段。
有人可以共享他们试图在模拟器中运行的功能代码,但该错误失败了吗? 越简单越好。
@samtstern以下代码对我而言失败:
import * as admin from 'firebase-admin';
admin.initializeApp();
import * as functions from 'firebase-functions';
export const testFunction = functions.https.onRequest(async (req, res) => {
const request = await admin.firestore().doc('test/123').get();
return request.ref.set({ test: 'random' })
.then(() => res.send('ok!'))
.catch((err) => res.status(500).send('error'));
});
仅当我在致电admin.initializeApp()
时设置服务帐户时才有效:
// this works
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
@wceolin对此表示感谢! 您可以在functions目录中运行以下命令吗?
$ npm list @google-cloud/firestore
这是我的结果(一切都对我有用):
functions@ /tmp/tmp.ZkMEM0XGPF/functions
└─┬ [email protected]
└── @google-cloud/[email protected]
我得到了相同的结果:
因此,我沿着错误堆栈跟踪以及此函数前进:
https://github.com/googleapis/gax-nodejs/blob/e1be4ebcc2287c61d5f1884033449e3b4e143242/src/grpc.ts#L141
我们有这个分支:
async _getCredentials(opts: ClientStubOptions) {
if (opts.sslCreds) {
return opts.sslCreds;
}
const grpc = this.grpc;
const sslCreds = grpc.credentials.createSsl();
const client = await this.auth.getClient();
const credentials = grpc.credentials.combineChannelCredentials(
sslCreds,
grpc.credentials.createFromGoogleCredential(client)
);
return credentials;
}
在我的代码中定义了opts.sslCreds
,所以我点击了这个分支:
if (opts.sslCreds) {
return opts.sslCreds;
}
这是另一个试图汇编凭据并引起问题的分支。 现在,我需要弄清楚为什么我的代码采用一种方式而您的代码采用另一种方式。
@wceolin你能达到到您的node_modules
文件夹和编辑文件functions/node_modules/google-gax/build/src/grpc.js
有console.log()
一个打印options
的对象createStub
功能,让我知道您看到了什么?
到目前为止,谢谢您的帮助!
@samtstern不确定是否有帮助,但是我在周末对我的package.json和node_modules做了很多调整。 我在7.0.2上不再遇到此问题。
npm list @google-cloud/firestore
输出与您的输出匹配。
我在周末取消了我的node_modules目录,所以我想知道这是否相关。
@noelmansour感谢您的
@noelmansour我还尝试删除node_modules
, yarn.lock
,删除依赖项,但这对我不起作用。 我将尝试从头开始创建一个项目,看看会发生什么。
@noelmansour这是我从options
对象中得到的:
{
"clientConfig": {},
"port":443,
"servicePath":"firestore.googleapis.com",
"credentials":{},
"projectId":"my-test-project",
"firebaseVersion":"8.2.0",
"libName":"gccl",
"libVersion":"2.2.3 fire/8.2.0",
"scopes":[
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/datastore"
]
}
@wceolin谢谢,这非常有帮助,因为这是我的样子(以及它的样子):
{
"clientConfig":{},
"port":8080,
"servicePath":"localhost",
"credentials":{},
"projectId":"fir-dumpster",
"firebaseVersion":"8.2.0",
"libName":"gccl",
"libVersion":"2.2.3 fire/8.2.0",
"service":"firestore.googleapis.com",
"sslCreds":{
"callCredentials": {}
},
"customHeaders":{
"Authorization":"Bearer owner"
},
"scopes":[
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/datastore"
]
}
如您所见,您的客户端仍在尝试访问生产,然后失败,因为未授权功能仿真器这样做。
您还在运行Firestore模拟器吗? 您的目标是写到Firestore模拟器还是您实际上要写到生产Firestore?
哦,我完全有能力重现此事! 如果我运行firebase emulators:start --only functions
然后尝试写入Firestore,则会收到此错误。
我看到以下日志消息:
⚠ The Cloud Firestore emulator is not running so database operations will fail with a 'default credentials' error.
这不再完全正确(错误是关于client_email的问题),但检测仍然正确。 这里的其他人也看到此警告吗?
这里有一些更多的信息可能会有所帮助。 在周末,我还在.zshrc中明确设置了Firestore Emulator env变量:
export FIRESTORE_EMULATOR_HOST="localhost:8080"
当我删除它时,我得到了错误。 这是命令firebase emulators:start
@noelmansour您可以使用--debug
运行该命令,并将日志作为txt
文件附加到这里吗?
@samtstern有时我使用模拟器在本地提供HTTP功能,该功能在生产中设置一些数据(通常是进行一些数据迁移)。 我正在使用:
firebase serve --only functions --project myProjectAlias
我不确定它是否应该那样工作(允许我们将数据写入生产环境),但是它曾经可以工作。 😅
@wceolin在6.8.0
之后的版本中,裸露的initializeApp()
不能这样工作。 我也有该用例,但我们希望找到一种选择加入的方式,以便默认方式是保护生产。
但我很高兴知道此错误从何而来!
@samtstern只是要确认,在未设置FIRESTORE_EMULATOR_HOST
运行firebase emulators:start --debug
,对吗?
正确!
在2019年7月1日星期一,下午12:28诺埃尔·曼苏尔[email protected]写道:
@samtstern https://github.com/samtstern只是为了确认,运行firebase
emulators:start --debug,未设置FIRESTORE_EMULATOR_HOST,对吗?-
您收到此邮件是因为有人提到您。
直接回复此电子邮件,在GitHub上查看
https://github.com/firebase/firebase-tools/issues/1451?
或使线程静音
https://github.com/notifications/unsubscribe-auth/ACATB2WG4EAD5KU7YRB5AUTP5JLGBANCNFSM4H4GTWIQ
。
这里是。
仅供参考,我从此行中删除了项目ID(不要紧):
[2019-07-01T19:32:42.859Z] >>> HTTP REQUEST GET https://mobilesdk-pa.googleapis.com/v1/projects/<project-id>:getServerAppConfig
同样值得一提的是,在不导出env变量的情况下, firebase-tools @ 7.0.1给了我这个错误:
⚠ Error: Getting metadata from plugin failed with error: Header field "authorization" must have only a single value
at Http2CallStream.call.on (/Users/noel/dev/snowble/functions/node_modules/@grpc/grpc-js/build/src/call.js:68:41)
at emitOne (events.js:121:20)
at Http2CallStream.emit (events.js:211:7)
at process.nextTick (/Users/noel/dev/snowble/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:71:22)
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9)
⚠ Your function was killed because it raised an unhandled error.
感谢@noelmansour提供的那些日志。 您还介意展示您的函数代码吗?
这有点棘手,因为我不想共享所有功能,并且我现在没有时间验证孤立地再现错误,但这是我一直在运行的hello函数:
index.ts:
require('./common'); // this should always be first in this file
export * from './debug'
// other exports for other functions
common.ts:
import * as admin from 'firebase-admin';
export const app = admin.initializeApp();
debug.ts:
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import {app} from "./common";
export const hello = functions.https.onRequest(async (req, resp) => {
const firestore = app.firestore();
const users = await firestore.collection('users').get();
console.log('empty users collection? ' + users.empty);
resp.sendStatus(200);
});
package.json:
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"emulators": "npm run build && firebase emulators:start",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/tasks": "^1.1.0",
"@types/jsonwebtoken": "^8.3.2",
"@types/request-promise": "^4.1.42",
"firebase-admin": "^8.2.0",
"firebase-functions": "^3.0.2",
"request": "^2.88.0",
"request-promise": "^4.2.4"
},
"devDependencies": {
"tslint": "^5.12.0",
"typescript": "^3.2.2"
},
"private": true
}
@noelmansour谢谢! 那只是向我揭示了一个错误。 这两件事应该相同,但不相同:
选项1
admin.initializeApp();
const firestore = admin.firestore();
选项2
const app = admin.initializeApp();
const firestore = app.firestore();
是的,这为我解决了。 谢谢!
我也遇到Error: The incoming JSON object does not contain a client_email field
错误。 无法修复。
默认代码:
import { initializeApp } from 'firebase-admin';
// Initiate Firebase app
export const app = initializeApp();
export const db = app.firestore();
export const auth = app.auth();
另一种尝试:
import { initializeApp, firestore, auth as defAuth } from 'firebase-admin';
// Initiate Firebase app
export const app = initializeApp();
export const db = firestore();
export const auth = defAuth();
另一种尝试:
import * as admin from 'firebase-admin';
// Initiate Firebase app
export const app = admin.initializeApp();
export const db = admin.firestore();
export const auth = admin.auth();
@JFGHT您使用什么命令来运行模拟器? 您可以使用--debug
标志显示命令和运行日志吗?
_免责声明:不确定我的问题和这里的问题有什么关系,但至少我可以在这里放下我的信息,因为这可能会帮助一些人。
我在firebase函数中具有相同的功能,该函数试图批量更新firestore数据库中的某些文档。 (没有批量测试)。
这是调用栈:
Unhandled error Error: The incoming JSON object does not contain a client_email field
> at JWT.fromJSON (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\google-auth-library\build\src\auth\jwtclient.js:165:19)
> at GoogleAuth.fromJSON (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\google-auth-library\build\src\auth\googleauth.js:294:16)
> at GoogleAuth.getClient (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\google-auth-library\build\src\auth\googleauth.js:476:52)
> at GrpcClient._getCredentials (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\google-gax\build\src\grpc.js:107:40)
> at GrpcClient.createStub (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\google-gax\build\src\grpc.js:223:34)
> at new FirestoreClient (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\@google-cloud\firestore\build\src\v1\firestore_client.js:128:39)
> at ClientPool.Firestore._clientPool.pool_1.ClientPool [as clientFactory] (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\@google-cloud\firestore\build\src\index.js:315:26)
> at ClientPool.acquire (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\@google-cloud\firestore\build\src\pool.js:61:35)
> at ClientPool.run (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\@google-cloud\firestore\build\src\pool.js:114:29)
> at Firestore.readStream (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\@google-cloud\firestore\build\src\index.js:995:26)
RESPONSE RECEIVED FROM FUNCTION: 500, {
"error": {
"status": "INTERNAL",
"message": "INTERNAL"
}
}
我正在使用命令行在本地运行函数:
firebase functions:shell
我正在使用此代码:
// Reference report in Firestore
const db = admin.firestore();
admin.initializeApp();
export const performMyCallableFirebaseFunction = (db,, { from, to }) => {
return db.collection("collectionName").where("prop", "==", from).limit(500).get().then(snapshot => {
if (snapshot.empty) return new Promise(resolve => resolve(`No docs found with prop: ${from}`));
const batch = db.batch();
snapshot.forEach(doc => batch.update(doc.ref, { prop: to }));
return batch.commit();
});
};
exports.myCallableFirebaseFunction = functions.https.onCall(data => performMyCallableFirebaseFunction(db, data.from, data.to));
我换了线admin.initializeApp();
至admin.initializeApp({ credential: admin.credential.applicationDefault() });
现在我可以使用以下命令在本地调用函数:
firebase functions:shell
firebase > myCallableFirebaseFunction({from: "foo", to: "bar"})
@samtstern
concurrently --kill-others 'GOOGLE_APPLICATION_CREDENTIALS=service-account.json firebase serve --only functions' 'tsc --project ./ --watch'
关于日志,今天不能,对不起!
我换了线
admin.initializeApp();
至admin.initializeApp({ credential: admin.credential.applicationDefault() });
这对我有用。 我通过以下方式在本地运行函数:
firebase serve --only functions
我不清楚这是否可以安全生产。 从文档中听起来,这将使管理员可以访问在生产环境中运行的代码,但是无论如何都是如此。
@ ralphsmith80嗯,您可能是对的:
自动查找凭证
GCP客户端库使用一种称为“应用程序默认凭据”(ADC)的策略来查找应用程序的凭据。 当您的代码使用客户端库时,该策略将按以下顺序检查您的凭据:
首先,ADC检查是否设置了环境变量GOOGLE_APPLICATION_CREDENTIALS。 如果设置了变量,则ADC使用变量指向的服务帐户文件。 下一节将介绍如何设置环境变量。
如果未设置环境变量,则ADC使用Compute Engine,Kubernetes Engine,App Engine和Cloud Functions提供的默认服务帐户为在这些服务上运行的应用程序。
如果ADC无法使用以上任一凭据,则会发生错误。
在测试和试验时,此策略很有用,但可能使您很难分辨出您的应用程序正在使用哪个凭据。
来源: https :
我换了线
admin.initializeApp();
至admin.initializeApp({ credential: admin.credential.applicationDefault() });
这种方法给我带来了一个全新的错误。
Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/Users/otanriverdi/Projects/socialpong/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)
at process._tickCallback (internal/process/next_tick.js:68:7)
我也在初始化商店,如您在#1454中所述
admin.initializeApp();
const db = admin.firestore();
加上initializeApp
凭证,我得到了上面的错误。
没有它,我仍然会得到;
Error: The incoming JSON object does not contain a client_email field
at JWT.fromJSON (/Users/otanriverdi/Projects/socialpong/functions/node_modules/google-auth-library/build/src/auth/jwtclient.js:165:19)
at GoogleAuth.fromJSON (/Users/otanriverdi/Projects/socialpong/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:294:16)
at GoogleAuth.getClient (/Users/otanriverdi/Projects/socialpong/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:476:52)
at GrpcClient._getCredentials (/Users/otanriverdi/Projects/socialpong/functions/node_modules/google-gax/build/src/grpc.js:107:40)
at GrpcClient.createStub (/Users/otanriverdi/Projects/socialpong/functions/node_modules/google-gax/build/src/grpc.js:223:34)
at new FirestoreClient (/Users/otanriverdi/Projects/socialpong/functions/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:128:39)
at ClientPool.Firestore._clientPool.pool_1.ClientPool [as clientFactory] (/Users/otanriverdi/Projects/socialpong/functions/node_modules/@google-cloud/firestore/build/src/index.js:315:26)
at ClientPool.acquire (/Users/otanriverdi/Projects/socialpong/functions/node_modules/@google-cloud/firestore/build/src/pool.js:61:35)
at ClientPool.run (/Users/otanriverdi/Projects/socialpong/functions/node_modules/@google-cloud/firestore/build/src/pool.js:114:29)
at Firestore.readStream (/Users/otanriverdi/Projects/socialpong/functions/node_modules/@google-cloud/firestore/build/src/index.js:995:26)
我在基本教程(教程来自2019年6月)上遇到了相同的错误,所以这个错误看起来很新...
INDEX.JS:
const函数= require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
admin.firestore()
.collection('screams')
.add(newScream)
.then(doc => {
res.json({message: `document ${doc.id} created successfully`});
})
.catch(err => {
res.status(500).json({ error: 'oops, something went wrong'});
console.error(err);
});
});
当我在Postman中运行端点时,我得到了错误消息
“错误”:“糟糕,出了点问题”
控制台说明:
功能:开始执行“ createScream”
错误:传入的JSON对象不包含client_email字段
教程来自FreeCodeCamp- https://www.youtube.com/watch? v
Firebase控制台>设置(齿轮图标)>用户和权限>服务帐户
生成新密钥。
将json添加到您的项目文件夹。
var admin = require("firebase-admin");
var serviceAccount = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://lts-profile.firebaseio.com"
});
服务帐户json文件使您的Firebase服务和功能可用于您的项目。
它应该始终是私有的。 在.gitignore中包含文件
Firebase控制台>设置(齿轮图标)>用户和权限>服务帐户
生成新密钥。
将json添加到您的项目文件夹。
var admin = require("firebase-admin"); var serviceAccount = require("path/to/serviceAccountKey.json"); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), databaseURL: "https://lts-profile.firebaseio.com" });
服务帐户json文件使您的Firebase服务和功能可用于您的项目。
它应该始终是私有的。 在.gitignore中包含文件
谢谢phtn,感激不尽-我已按照您的指示进行操作,但现在出现错误
Error: Error occurred while parsing your function triggers.
奇怪的是,当我运行“ firebase deploy”时,所有内容都在运行:' https://europe-west1-myapp.cloudfunctions.net/api / ...-不在本地主机上吗?
serviceAccountKey.json应该在/functions
目录中。
firebase deploy --only functions
会在外面抱怨。
再次感谢(非常耐心!)。 我的serviceAccountKey.json在/ functions文件夹中(请参阅下面的链接中的screen-grab)。
看来,有三种方法可以初始化应用程序...我已经分别尝试了这三种方法,但它们似乎都不起作用-我觉得这简直是我所缺少的疯狂方法。
d
屏幕抓取:
我们最终遇到了同样的问题。 我们正在以下模型下初始化firebase:
const firebaseInstance = admin.initializeApp()
const firestoreInstance = firebaseInstance.firestore()
让我知道我们是否可以提供任何帮助进行跟踪。
这个线程上的每个人。 我们找到了解决方案。 我们将firebase-tools从7.0.2降级到7.0.1,并收到了一个完全不同的错误(关于无法加载默认凭据的信息)。
因此,我们继续运行:
gcloud auth application-default login
这解决了我们的问题
@ryanhornberger,您可以通过以下方法解决问题:
const firebaseInstance = admin.initializeApp()
const firestoreInstance = admin.firestore() // I changed this line
我已经解决了#1459中的问题
@samtstern谢谢!
这个线程上的每个人。 我们找到了解决方案。 我们将firebase-tools从7.0.2降级到7.0.1,并收到了一个完全不同的错误(关于无法加载默认凭据的信息)。
因此,我们继续运行:
gcloud auth application-default login
这解决了我们的问题
这对我有用。 我最初将firebase-tools升级到7.1,当我在本地运行“ firebase serve”时遇到“相同错误”。 但是,如果我部署到Firebase,它工作正常。 降级至7.0.1在我本地就可以使用。
7.1同样的问题
我们正在修复,但尚未准备好:
https://github.com/firebase/firebase-tools/pull/1479
我坚持下去,有什么办法吗?
降级到7.0.1对我没有帮助
对此的修复程序已合并到#1479中,并将包含在下一个版本中(因此7.2.0
)
嘿@samtstern ,不确定这是我做错的东西,还是可能有几个新问题,但是我注意到有一些事情使工具无法使用最新的master(dad143c42445056014f6f48cc9dfa13156e3c186)。
首先,在运行firebase emulators:exec "npm run test"
时收到以下警告:
⚠ The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
即使在命令的前面,我仍然可以看到它启动了模拟器:
~/d/s/functions ❯❯❯ firebase emulators:exec "npm run test" ✘ 130
i Starting emulators: ["functions","firestore"]
✔ functions: Using node<strong i="12">@8</strong> from host.
✔ functions: Emulator started at http://localhost:5001
i firestore: Logging to firestore-debug.log
✔ firestore: Emulator started at http://localhost:8080
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
它实际上不是在更新生产Firestore数据库。 也许只是假阴性?
另一个问题是我仍然遇到错误。 我没有设置$GOOGLE_APPLICATION_CREDENTIALS
,但是根据https://firebase.google.com/docs/functions/local-emulator#set_up_admin_credentials_optional的规定,如果仅访问firestore,应该已经有足够的权限:
Cloud Firestore和实时数据库触发器已经具有足够的凭据,并且不需要其他设置。
我正在使用admin.initializeApp();
初始化不带任何参数的admin sdk也许我做错了什么?
@noelmansour感谢您报告此问题(并尝试master
!)您可以显示主要功能文件的代码吗?
几乎可以肯定是一个假阴性,但我们需要解决一个重要的错误。
这是最小的,因为它只是从其他文件中导出:
import * as admin from 'firebase-admin';
// this should happen before any function runs
admin.initializeApp();
export * from './authFunctions';
export * from './fitbit';
export * from './sleep'
export * from './scheduler';
export * from './debug'
export {scheduleFunction} from "./scheduler";
实际上,这似乎与我的测试设置有关。 运行firebase emulators:start
我看不到警告。
@noelmansour您的测试是什么样的? 您也可以提出新的问题来讨论此问题,以便我们不会在此线程上向所有人发送垃圾邮件>
当然是。 我很抱歉。 第1530章开
这个线程上的每个人。 我们找到了解决方案。 我们将firebase-tools从7.0.2降级到7.0.1,并收到了一个完全不同的错误(关于无法加载默认凭据的信息)。
因此,我们继续运行:gcloud auth application-default login
这解决了我们的问题
这对我有用。 我最初将firebase-tools升级到7.1,当我在本地运行“ firebase serve”时遇到“相同错误”。 但是,如果我部署到Firebase,它工作正常。 降级至7.0.1在我本地就可以使用。
您能告诉我如何降级Firebase版本吗? 我现在的版本是7.0.2,然后我尝试安装NPM我[email protected] -g这一点。 但我的版本仍然是7.0.2。 如何降级请帮助?
Firebase功能也有同样的问题。 已经尝试使用npm install -g [email protected]导致相同的错误。
Firebase功能也有同样的问题。 已经尝试使用npm install -g [email protected]导致相同的错误。
以下解决方案为我工作:
// Create Firebase-adminsdk key
// Providing a service account object inline
admin.initializeApp({
credential: admin.credential.cert({
projectId: "<PROJECT_ID>",
clientEmail: "foo@<PROJECT_ID>.iam.gserviceaccount.com",
privateKey: "-----BEGIN PRIVATE KEY-----<KEY>-----END PRIVATE KEY-----\n"
})
});
最有用的评论
_免责声明:不确定我的问题和这里的问题有什么关系,但至少我可以在这里放下我的信息,因为这可能会帮助一些人。
我在firebase函数中具有相同的功能,该函数试图批量更新firestore数据库中的某些文档。 (没有批量测试)。
这是调用栈:
我正在使用命令行在本地运行函数:
firebase functions:shell
我正在使用此代码:
我换了线
admin.initializeApp();
至
admin.initializeApp({ credential: admin.credential.applicationDefault() });
现在我可以使用以下命令在本地调用函数:
请参阅docs.admin.credential.applicationDefault()