解析错误:尝试部署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。

回答

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

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

parserOptions: {
  ecmaVersion: 8 // or 2017
}

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


以上是解析错误:尝试部署Firebase云功能时出现意外令牌=&gt;。我在这里找不到任何答案的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>