Rasit aydin
Rasit aydin

Reputation: 469

React Unexpected Token with Async

I am trying to define a function as you see below.

const fetchRoles = async () => {
      const fetchedRoles = await axiosInstance.get('/roles/');
      setRoles(fetchedRoles.data)
}

And I am getting error "Unexpected token () ^=>". Why I am getting this error ? I am using node version v12.18.2 and npm version 6.14.7

Thanks..

Upvotes: 0

Views: 95

Answers (1)

Rasit aydin
Rasit aydin

Reputation: 469

I solved the problem. For their person who may experience this problem, This error comes from eslint-loader. So I updated eslint config with ecmaVersio 8 and problem solved.

My parser conf,

"parserOptions": {
    "ecmaVersion": 8,
    "sourceType": "module",
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true,
      "jsx": true
    }
  }

Upvotes: 1

Related Questions