Massimo555
Massimo555

Reputation: 11

Parsing error: Can not use keyword 'await' outside an async function

Line 20:19: Parsing error: Can not use keyword 'await' outside an async function

  18 | 
  19 |     try{
  20 |       const res = await axios.post('/upload', formData, {
     |                   ^
  21 |         headers:{
  22 |           'Content-Type':'multipart/form-data'
  23 |         }

Upvotes: 1

Views: 1494

Answers (1)

Ugurcan
Ugurcan

Reputation: 49

You can't use directly await like this. You should create a function with async and then you can use await in function like that;

const myFunction = async () => {
  try {
    const res = await axios.get('bla')
  }
}

Upvotes: 3

Related Questions