Mike
Mike

Reputation: 1331

Error deploying to firebase cloud functions - ? configuration details missing

I've installed firebase tools on my mac. The firebase version i've got is 3.14.0

I think after reading this: https://firebase.google.com/docs/functions/config-env

All I need to do is run:

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

But if i'm wrong there is a long post below explaining my issue.

Thanks.


Using the guide at:

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

My directory structure looks pretty sound. The package.json file is below:

{
  "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
}

In the index.js file i've got three lines of code:

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

But when i run firebase deploy it halts at preparing functions for uploading.

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)

I've used firebase cloud functions before with a previous app and I got a bit of help installing initially and i recall maybe having to make some alterations to a config file with firebase functions. But I can't really recall. The only difference this time was when installing firebase tools I selected Firestore as well as firebase database.

I've also checked that i'm logged in with firebase login and i am.


Update:

I did have a look at:

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

I just wasn't sure which environment variables i needed to set.

There is the is post Cloud Functions for Firebase Error occurred while parsing your function triggers

About setting:

firebase functions:config:set gmail.email="[email protected]" gmail.password="gmailPassword"

But i'm logged in already with my email so wasn't sure if needed to set again.

There's also https://firebase.google.com/docs/admin/setup and a couple of lines about "If you are using the Node.js Admin SDK in a Cloud Function, you can automatically initialize the SDK through the functions.config() variable:" admin.initializeApp(functions.config().firebase);

There is this post also re: manually setting up a config file but wan't sure how relevant it is:

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

Thanks.

Upvotes: 2

Views: 3700

Answers (1)

Bob Snyder
Bob Snyder

Reputation: 38289

The closing tick mark in this statement is not correct. It should be a simple apostrophe like the opening tick, not a "right single quotation mark" (unicode 8217):

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

Change it to match the opening tick.

It's puzzling that the tick is correct in this code that you posted:

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

but not in the error output:

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

Upvotes: 3

Related Questions