I am getting the following error in async usage on ESLINT.
eslint Parsing error: Unexpected token function with async
Here is my
I was getting this error also, I added the following to my eslintrc:
{
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 8
}
}
It's an error regarding func-style
. By default it uses type expression
, and the correct way to represent functions using this as expression
is:
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
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.
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
});
}
In my case it got fixed when I just changed from:
"parserOptions": { "ecmaVersion": 8 }
to
"parserOptions": { "ecmaVersion": 2018 }