javascript - 解析错误:意外的令牌 => 尝试部署 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
。
推荐阅读
- react-native - 无法使用 React-Ntive 将 userId 作为参数发布
- c# - C# 将数据从 DataTable 更新到数据库(Winforms 应用程序)
- javascript - 切换数组VueJS中对象的属性?
- d3.js - 如何附加圆角矩形
- ios - IOS移动禁用缩放
- homebrew - ZooKeeper - 命令 zkCli 未连接
- reactjs - 执行 nginx -s reload 时出现“nginx:[emerg] host not found in upstream”错误
- javascript - 自动化的 JavaScript 文档工具可以将函数文字解析为函数吗?
- c++ - 未知的 CMake 命令“check_language”
- perl - 保存对本地化文件句柄的引用。它是如何工作的?