Reputation: 4388
i am trying to follow the tutorial at https://codelabs.developers.google.com/codelabs/firebase-cloud-functions/#7 and I am getting the "Error occurred while parsing your function triggers" error. firebase-tools verson is 5.6.0. What I am doing wrong?
Stack Trace:
C:\Users\user\Downloads\friendlychat-web-master\cloud-functions-start\functions>firebase deploy --only functions
=== Deploying to 'friendlychat'...
i deploying functions
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
Error: Error occurred while parsing your function triggers.
C:\Users\user\Downloads\friendlychat-web-master\cloud-functions-start\functions\index.js:23
exports.addWelcomeMessages = functions.auth.user().onCreate(async(user)=>{
^
SyntaxError: Unexpected token (
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at C:\Users\user\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:21:11
functions\index.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.addWelcomeMessages = functions.auth.user().onCreate(async(user)=>{
const fullName = user.displayName || 'Anonymous';
await admin.database().ref('messages').push({
name: 'Firebase Bot',
profilePicUrl: '/images/firebase-logo.png', // Firebase logo
text: `${fullName} signed in for the first time! Welcome!`,
});
});
functions\Package.json:
{
"name": "friendlychat-codelab",
"description": "Firebase SDK for Cloud Functions codelab",
"dependencies": {
"firebase-admin": "~5.13.1",
"firebase-functions": "^2.0.0"
},
"devDependencies": {
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0"
},
"engines": {
"node": "8"
},
"private": true
}
Upvotes: 0
Views: 528
Reputation: 317352
The instructions at the beginning of the codelab require you to be using nodejs 8. You're probably using an older version, which doesn't support async/await.
Check your node version with this:
node --version
It should be version 8. If it's not, you'll have to replace it.
Upvotes: 2