Firebase部署找不到serviceAccountKey [英] Firebase deploy can't find serviceAccountKey

查看:50
本文介绍了Firebase部署找不到serviceAccountKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将serviceAccountKey添加到我的云函数项目(Typescript)

I'm trying to add a serviceAccountKey to my cloud functions project (Typescript)

var serviceAccount = require("/Users/kareldebedts/myAppName/functions/serviceAccountKeyName.json");

admin.initializeApp({
  storageBucket: "appName.appspot.com",
  credential: admin.credential.cert(serviceAccount),
});

当我部署函数时,出现此错误:

When I deploy my functions I get this error:

Deployment error.
Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module '/Users/kareldebedts/myAppName/functions/serviceAccountKeyName.json'

我做错了什么?因为如果我单击cmd会打开文件,所以该路径存在.

What Am I doing wrong? Because if i cmd click on the path it opens the file, so the path exists.

推荐答案

编写Cloud Functions时,不应在计算机上使用本地文件路径.它仅包含从功能"文件夹中部署的文件.因此,您应该将服务帐户文件与源代码一起放入函数文件夹中,并使用 require('./serviceAccount.json')之类的文件将其移出那里.

You shouldn't use local file paths on your computer when writing Cloud Functions. It will only have available the files you deployed from your "functions" folder. So you should put the service account file in the functions folder along with your source code, and require it out of there with something like require('./serviceAccount.json').

这篇关于Firebase部署找不到serviceAccountKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆