我正在尝试按照https://codelabs.developers.google.com/codelabs/firebase-cloud-functions/#7的教程进行操作,并且出现“解析函数触发器时发生错误”错误。 firebase-tools版本为5.6.0。 我做错了什么?
堆栈跟踪:
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
}
答案 0 :(得分:2)
代码实验室开头的说明要求您使用nodejs8。您可能正在使用较旧的版本,该版本不支持async / await。
使用以下方法检查您的节点版本:
node --version
它应该是版本8。如果不是,则必须替换它。