firebase-functions: 0.8.1
firebase-tools: 3.17.3
firebase-admin: 5.8.1
I've basic function which looks as follows
exports.returnSomething = functions.https.onRequest((req, res) => {
// doStuff does some stuff and returns a response.
return doStuff(req,res);
});
cd functions
npm i
functions start
firebase serve --only functions
Yes, deployment is working fine.
We have runtime config which I'm exporting to my local functions folder using firebase functions:config:get > .runtimeconfig.json. It has all "private_key" value (string) in it.
It should start serving function locally.
It does serve function locally but gives following error on firebase serve --only functions
straws-v:functions veggie.straws$ firebase serve --only functions
=== Serving from '/Users/veggie.straws/Sample/right-shift'...
i functions: Preparing to emulate functions.
Warning: You're using Node.js v9.4.0 but Google Cloud Functions only supports v6.11.1.
âš functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
âš functions: Error from emulator. FirebaseError: Error occurred while parsing your function triggers.
Error: Certificate object must contain a string "private_key" property.
at FirebaseAppError.FirebaseError [as constructor] (/Users/veggie.straws/Sample/right-shift/functions/node_modules/firebase-admin/lib/utils/error.js:39:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/veggie.straws/Sample/right-shift/functions/node_modules/firebase-admin/lib/utils/error.js:85:28)
at new FirebaseAppError (/Users/veggie.straws/Sample/right-shift/functions/node_modules/firebase-admin/lib/utils/error.js:119:28)
at new Certificate (/Users/veggie.straws/Sample/right-shift/functions/node_modules/firebase-admin/lib/credential.js:125:19)
at new CertCredential (/Users/veggie.straws/Sample/right-shift/functions/node_modules/firebase-admin/lib/credential.js:194:33)
at Object.cert (/Users/veggie.straws/Sample/right-shift/functions/node_modules/firebase-admin/lib/firebase-namespace.js:237:58)
at Object.<anonymous> (/Users/veggie.straws/Sample/right-shift/functions/index.js:11:40)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11
at Object.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:38:3)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
.runtimeconfig.json has same values as what firebase functions:config:get returns.
Tried installing latest version of firebase functions but no luck npm i --save firebase-functions
@pratiknikam Can you clarify what you mean by "It has all "private_key" value (string) in it."? So do you have a config variable with the key "private_key"?
How are you initializing firebase-admin? Are you doing admin.initializeApp(functions.config().firebase) or something else?
@laurenzlong Yes, I have a .runtimeconfig.json which has variable with the key "private_key".
const config = functions.config();
const fbConfig = functions.config().firebase;
fbConfig.credential = admin.credential.cert({
'private_key': replace(get(config, 'service_account.private_key'), /\\n/g, '\n')),
'client_email': get(config, 'service_account.email'),
'project_id': get(config, 'service_account.project_id')
});
admin.initializeApp(fbConfig);
.runtimeconfig.json looks as follows
{
"service_account": {
"private_key": "<private-key",
"email": "<email>",
"project_id": "<project-id>"
},
"firebase": {
"apiKey": "<api-key>",
"authDomain": "<auth-domain>",
"databaseURL": "<databas-url>",
"projectId": "<project-id>",
"storageBucket": "<storage-bucket>",
"messagingSenderId": "<sender-id>"
}
}
I see, this is a CLI bug which was fixed in master branch, and will be released in a few days. You can use it right away by running:
npm install -g https://github.com/firebase/firebase-tools.git
It was actually just released, so you can update to v3.17.4 of firebase-tools by running:
npm install -g firebase-tools
Most helpful comment
It was actually just released, so you can update to v3.17.4 of firebase-tools by running:
npm install -g firebase-tools