【问题标题】:Firebase deploy can't find serviceAccountKeyFirebase 部署找不到 serviceAccountKey
【发布时间】:2020-04-13 08:50:48
【问题描述】:

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

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

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

当我部署我的函数时,我得到了这个错误:

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 点击它打开文件的路径,所以路径存在。

【问题讨论】:

    标签: node.js typescript firebase google-cloud-functions


    【解决方案1】:

    在编写 Cloud Functions 时,您不应在计算机上使用本地文件路径。它只会提供您从“功能”文件夹中部署的文件。因此,您应该将服务帐户文件与源代码一起放在函数文件夹中,并使用require('./serviceAccount.json') 之类的东西将其从那里取出。

    【讨论】:

    • 谢谢,所以我把文件放在我的函数文件夹中,然后我添加了:require('./serviceAccount.json')。 (我正在使用打字稿)。我收到此错误:解析触发器时出错:找不到模块'./serviceAccountKeyName.json' 需要堆栈:- /Users/kareldebedts/myfolder/functions/lib/index.js - /usr/local/lib/node_modules/firebase-tools /lib/triggerParser.js
    • 好的,我找到了,你必须把文件放到functions/lib文件夹中。感谢您的帮助!
    • 实际上我不会使用 lib,因为那是转译代码的地方。我会将它放在函数文件夹中并使用“../serviceAccount.json”来要求它。
    猜你喜欢
    • 2019-03-20
    • 1970-01-01
    • 2019-12-12
    • 2018-03-31
    • 1970-01-01
    • 2018-03-31
    • 2022-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多