首页 > 解决方案 > 解析错误:意外的令牌 => 尝试部署 Firebase 云功能时。我在这里找不到任何答案

问题描述

exports.sendInvite = functions.firestore
  .document("invites/{phoneNumber}")
  .onCreate(async (doc) => { //error is here I assume
    const from = "+<mynumber>";
    const to = doc.data().phoneNumber;

    const text = "You can join the club now";

    return client.messages.create(from, to, text);
  });

我的 .eslintrc.js

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

我的 firebase 云功能抛出此错误Parsing error: Unexpected token =>。有谁知道为什么会这样?我正在使用 javascript 顺便说一句不是 TS。 在此处输入图像描述

标签: javascripteslint

解决方案


箭头函数是 ES6 的特性,但这里有一个异步箭头函数。

异步函数通常是ES8(或2017)特性。因此,您需要在配置的根目录中指定以下设置:

parserOptions: {
  ecmaVersion: 8 // or 2017
}

这将使解析器知道在使用=>之后期望令牌async


推荐阅读