【问题标题】:Error deploying to firebase cloud functions - ? configuration details missing部署到 Firebase 云功能时出错 - ?缺少配置详细信息
【发布时间】:2018-04-24 11:43:46
【问题描述】:

我已经在我的 Mac 上安装了 firebase 工具。 我的firebase版本是3.14.0

读完后我想: https://firebase.google.com/docs/functions/config-env

我需要做的就是运行:

firebase functions:config:set someservice.key="THE API KEY" someservice.id="THE CLIENT ID"

但如果我错了,下面有一个很长的帖子来解释我的问题。

谢谢。


使用指南:

https://firebase.google.com/docs/functions/get-started

我的目录结构看起来很合理。 package.json 文件如下:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase serve --only functions",
    "shell": "firebase experimental:functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "firebase-admin": "~5.4.2",
    "firebase-functions": "^0.7.1"
  },
  "private": true
}

在 index.js 文件中,我有三行代码:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

但是当我运行 firebase deploy 时,它会停止准备上传功能。

i  functions: preparing functions directory for uploading...

Error: Error occurred while parsing your function triggers.

/private/var/folders/1v/xxxxxxxxxxxxxxxxxxxxxxxx/T/xxxxxxxxxxxxxxxxxx/index.js:2
const admin = require('firebase-admin’);
                      ^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)

我之前在以前的应用程序中使用过 firebase 云功能,最初安装时我得到了一些帮助,我记得可能不得不对具有 firebase 功能的配置文件进行一些更改。但我真的想不起来了。这次唯一的不同是在安装 firebase 工具时,我选择了 Firestore 和 firebase 数据库。

我还检查了我是否已使用 firebase 登录名登录。


更新:

我确实看过:

https://firebase.google.com/docs/functions/config-env

我只是不确定需要设置哪些环境变量。

有帖子Cloud Functions for Firebase Error occurred while parsing your function triggers

关于设置:

firebase functions:config:set gmail.email="email@gmail.com" gmail.password="gmailPassword"

但是我已经用我的电子邮件登录了,所以不确定是否需要重新设置。

还有https://firebase.google.com/docs/admin/setup 和几行关于“如果您在 Cloud Function 中使用 Node.js Admin SDK,您可以通过 functions.config() 变量自动初始化 SDK:” admin.initializeApp(函数.config().firebase);

还有这篇文章是关于:手动设置配置文件,但不确定它的相关性:

How do you setup local environment variables for Cloud Functions for Firebase

谢谢。

【问题讨论】:

    标签: firebase google-cloud-functions


    【解决方案1】:

    此语句中的结束刻度线不正确。它应该是一个简单的撇号,比如开头的勾号,而不是“右单引号”(unicode 8217):

    const admin = require('firebase-admin’);
    

    更改它以匹配开头的刻度。

    令人费解的是,您发布的这段代码中的勾号是正确的:

    const functions = require('firebase-functions');
    const admin = require('firebase-admin');
    admin.initializeApp(functions.config().firebase);
    

    但不在错误输出中:

    /private/var/folders/1v/xxxxxxxxxxxxxxxxxxxxxxxx/T/xxxxxxxxxxxxxxxxxx/index.js:2
    const admin = require('firebase-admin’);
                          ^^^^^^^^^^^^^^^^^^
    

    【讨论】:

    • 谢谢!!!我正在阅读文档,所以我想我只是将他们的代码版本复制到了 stackoverflow 中,我怀疑我所做的一定是在尝试整理 index.js 文件时不小心删除了 ' ,而是用撇号替换了它。
    猜你喜欢
    • 1970-01-01
    • 2021-02-06
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 2021-12-01
    • 2019-09-30
    • 1970-01-01
    相关资源
    最近更新 更多