eslint Parsing error: Unexpected token function with async

后端 未结 4 2016
长情又很酷
长情又很酷 2021-02-04 00:09

I am getting the following error in async usage on ESLINT.

eslint Parsing error: Unexpected token function with async

Here is my

4条回答
  •  悲&欢浪女
    2021-02-04 00:44

    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.

提交回复
热议问题