google firebase 函数教程 意外令牌 => [英] google firebase function tutorial unexpected token =>

查看:23
本文介绍了google firebase 函数教程 意外令牌 =>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了一些谷歌搜索,但没有找到我的问题的答案.我正在关注 google firebase 函数的教程 here 并拥有index.js 完全从教程链接的 GitHub 存储库中复制,并按照教程复制块"中的代码,运行 firebase deploy --only 函数后出现此错误

I have done some googling and haven't found an answer to my question. I am following the tutorial for google firebase functions here and have copied index.js exactly from the GitHub repository linked on the tutorial as well as copying the code in 'chunks' by following the tutorial and I get this error after running firebase deploy --only functions

error 解析错误:Unexpected token =>

引用了这个函数:

exports.addMessage = (functions.https.onRequest(async (req, res) => { //This line
    // [END addMessageTrigger]
    // Grab the text parameter.
    const original = req.query.text;
    // [START adminSdkAdd]
    // Push the new message into Firestore using the Firebase Admin SDK.
    const writeResult = await admin.firestore().collection('messages').add({ original: original });
    // Send back a message that we've successfully written the message
    res.json({ result: `Message with ID: ${writeResult.id} added.` });
    // [END adminSdkAdd]
}));

链接到教程中使用的 index.js 文件

我的 eslintrc.js 文件:

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    "eslint:recommended",
    "google",
  ],
  rules: {
    quotes: ["error", "double"],
  },
};

推荐答案

在 ECMAScript 2017 中添加了异步函数和 await 关键字.您需要将 ecmaVersion 设置为 8你的 ESLint 配置.

Async functions and await keyword were added in ECMAScript 2017. You need to set ecmaVersion to 8 in your ESLint config.

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    "eslint:recommended",
    "google",
  ],
  parserOptions: {
    ecmaVersion: 8
  },
  rules: {
    quotes: ["error", "double"],
  },
};

这篇关于google firebase 函数教程 意外令牌 =>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆