javascript - Javascript,意外令牌 =>
问题描述
尝试编写要部署到 firebase 的 javascript 函数时出现以下错误:
解析错误:意外的令牌 =>
在代码:
exports.sendFriendRequest = functions.firestore.document("requests/{rUid}").
onWrite(async (event) => {
const userId1 = event.after.get("userId1");
const userId2 = event.after.get("userId2");
let userName1 = await admin.firestore().doc("users/${userId1}/name").get();
console.log(userName1);
const title = "New friend request";
const content = "${userName1} wants to be your friend";
console.log(content);
let user2 = await admin.firestore().doc("users/${userId2}").get();
let fcmToken = user2.get("fcm");
// let userDoc = await admin.firestore().doc('users/${uid}').get();
// let fcmToken = userDoc.get('fcm');
var message = {
notification: {
title: title,
body: content,
},
token: fcmToken,
}
let response = await admin.messaging().send(message);
console.log(response);
});
所有的括号都匹配,我的节点版本是 14.16.1。我不知道为什么我会得到这个,有什么想法吗?我在下面上传了一张带有代码的图片。
解决方案
使用您当前的配置,ESLint 不了解async
/await
语法是什么。
您需要打开您的.eslintrc.js
(或.eslintrc.*
)文件,并确保它ecmaVersion
至少是版本8 (ES2017)。有关更多信息,请参阅文档。
// for .eslintrc.js
module.exports = {
/* ... other settings ... */
"parserOptions": {
"ecmaVersion": 8,
/* ... other settings ... */
},
/* ... other settings ... */
}
推荐阅读
- git - 设置 Windows 凭据管理器并将其推送到 repo
- docker - 我的管道不允许我通过 golang 连接,尽管它在开发环境中工作
- tensorflow - 如何在 TF 2.0 / 1.14.0-eager 和自定义训练循环(梯度磁带)中执行梯度累积?
- r - 在两个不同的列中满足两个条件的观察百分比(以 r 为单位)
- html - 无论屏幕大小如何,都能保持图像分辨率
- c++ - 在两个Raspberry Pis c ++之间发送重复命令的方法
- r - 如何根据应用于数据集的月份序列创建按月份和年份命名的虚拟变量?
- reactjs - 如何在 React 功能组件中使用 AfterJS getInitialProps
- javascript - 将 D3 与 React 结合使用的最优化方式是什么?
- angular - 在下拉列表中设置选定值