[英]eslint Parsing error: Unexpected token function with async
I am getting the following error in async usage on ESLINT.我在 ESLINT 的异步使用中遇到以下错误。
eslint Parsing error: Unexpected token function with async
eslint 解析错误:带有异步的意外令牌函数
Here is my eslintsrc
这是我的
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
}
}
UPDATE更新
Here is my async这是我的异步
const get = async function get(req, res) {
const user = await service.get();
console.log("From db",user.username);
res.send('ok');
};
I was getting this error also, I added the following to my eslintrc:我也收到此错误,我在 eslintrc 中添加了以下内容:
{
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 8
}
}
In my case it got fixed when I just changed from:在我的情况下,当我刚从以下位置更改时它得到了修复:
"parserOptions": { "ecmaVersion": 8 }
“解析器选项”:{“ecmaVersion”:8}
to到
"parserOptions": { "ecmaVersion": 2018 }
“解析器选项”:{“ecmaVersion”:2018}
It's an error regarding func-style
.这是关于
func-style
的错误。 By default it uses type expression
, and the correct way to represent functions using this as expression
is:默认情况下,它使用类型
expression
,使用 this 作为expression
来表示函数的正确方法是:
const get = async get(req, res) {
const user = await service.get();
console.log("From db",user.username);
res.send('ok');
};
Check the docs for further examples, https://eslint.org/docs/rules/func-style检查文档以获取更多示例, https://eslint.org/docs/rules/func-style
UPDATE: Forgot to see you have added error, what you were doing was right,更新:忘记看到你添加了错误,你在做什么是对的,
const get = async function get(req, res) {
const user = await service.get();
console.log("From db",user.username);
res.send('ok');
};
Just remove func-style
from eslint.只需从 eslint 中删除
func-style
。
If you are new in the project I recommend just to go back with promises :)如果你是这个项目的新手,我建议你带着承诺回去:)
function openTabs(array) {
return new Promise((resolve, reject) => {
//... your code
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.