【发布时间】:2021-06-01 21:36:50
【问题描述】:
我对 firebase 云功能相当陌生,我正在尝试创建一个云功能,它将向 firebase 上新创建的用户发送电子邮件(我将首先使用日志对其进行测试),但我一直报错解析错误:Unexpected token =>
这是 index.js 代码
const functions = require("firebase-functions");
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
exports.onUserCreate = functions.firestore.document('users/{usersId}').onCreate(async (snap, context) => {
const values = snap.data();
//send email
await db.collection('logging').add({ description: `Email was sent to user with nickname:${values.username}` });
})
这是.eslintrc.js
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
ecmaVersion: 6,
},
env: {
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'google',
],
rules: {
'generator-star-spacing': 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
},
};
这是 package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "14"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
"devDependencies": {
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
非常感谢任何帮助。谢谢!
【问题讨论】:
标签: javascript google-cloud-functions