![](/img/trans.png)
[英]Including Async Function Within Firebase Cloud Functions (eslint "Parsing error: Unexpected token function")
[英]eslint Parsing error: Unexpected token function with async
我在 ESLINT 的異步使用中遇到以下錯誤。
eslint 解析錯誤:帶有異步的意外令牌函數
這是我的eslintsrc
{
"extends": "airbnb-base",
"rules": {
"no-console": "off",
"func-style":"error",
"import/no-extraneous-dependencies": ["error", {"devDependencies": false, "optionalDependencies": false, "peerDependencies": false, "packageDir": "./"}]
},
"parserOptions": {
"ecmaVersion":8
}
}
更新
這是我的異步
const get = async function get(req, res) {
const user = await service.get();
console.log("From db",user.username);
res.send('ok');
};
我也收到此錯誤,我在 eslintrc 中添加了以下內容:
{
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 8
}
}
在我的情況下,當我剛從以下位置更改時它得到了修復:
“解析器選項”:{“ecmaVersion”:8}
到
“解析器選項”:{“ecmaVersion”:2018}
這是關於func-style
的錯誤。 默認情況下,它使用類型expression
,使用 this 作為expression
來表示函數的正確方法是:
const get = async get(req, res) {
const user = await service.get();
console.log("From db",user.username);
res.send('ok');
};
檢查文檔以獲取更多示例, https://eslint.org/docs/rules/func-style
更新:忘記看到你添加了錯誤,你在做什么是對的,
const get = async function get(req, res) {
const user = await service.get();
console.log("From db",user.username);
res.send('ok');
};
只需從 eslint 中刪除func-style
。
如果你是這個項目的新手,我建議你帶着承諾回去:)
function openTabs(array) {
return new Promise((resolve, reject) => {
//... your code
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.