我对firebase云函数还很陌生,我正在尝试创建一个云函数,该函数将向firebase上新创建的用户发送一封电子邮件(我将首先使用日志进行测试(,但我一直遇到错误分析错误:意外的令牌=>
这是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',
},
};
这是包.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
}
任何帮助都将不胜感激。谢谢
您面临的问题的两种可能的解决方案是将package.json
中的脚本部分更改为以下内容:
"scripts": {
"lint": "eslint",
...
},
因此,从中删除.
,它是自动生成的,但可能会导致此类问题。
此外,您还可以将解析器的ecmaVersion
更改为版本8,因此将.eslintrc.js
文件更改为:
parserOptions: {
parser: 'babel-eslint',
ecmaVersion: 8,
},
这可能是您的esint理解async/await
表示法所需要的。