SyntaxError: unexpected reserved word 'await' in async function

angie

Here is my code. Can't figure out why the error occured. The function is async type.

const func = async () => {
      {submission[0].emoticons.map((item, idx) => {
        console.log('apngToFrame is working')
        const imgsrc = `${url}${item.id}`
        var container2 = document.querySelector('.output2')
        const response = await fetch(imgsrc)
        const buffer = await response.arrayBuffer()
        const apng = parseAPNG(buffer)
        if (apng instanceof Error){
          console.error('apng.message', apng.message)
          return ;
        }
        await apng.createImages()
        apng.frames.forEach(f => {
          container2.appendChild(f.imageElement)
        })
      })}
    }

sanket naik

Add async for the callback function that you are using in the map

const func = async () => {
      {submission[0].emoticons.map(async(item, idx) => {
        console.log('apngToFrame is working')
        const imgsrc = `${url}${item.id}`
        var container2 = document.querySelector('.output2')
        const response = await fetch(imgsrc)
        const buffer = await response.arrayBuffer()
        const apng = parseAPNG(buffer)
        if (apng instanceof Error){
          console.error('apng.message', apng.message)
          return ;
        }
        await apng.createImages()
        apng.frames.forEach(f => {
          container2.appendChild(f.imageElement)
        })
      })}
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

for await gives SyntaxError: Unexpected reserved word inside a async function

Unexpected reserved word 'await' in async function in react

SyntaxError: Unexpected reserved word "await"

SyntaxError: Unexpected reserved word, for await loop

Unexpected reserved word 'await'

Await is a reserved word error inside async function

Await is a reserved word error inside async function

SyntaxError: Unexpected token function - Async Await Nodejs

SyntaxError: Unexpected reserved word on typescript

SyntaxError: Unexpected reserved word on running mocha with enzyme

Firestore: Uncaught SyntaxError: Unexpected reserved word

Uncaught SyntaxError: Unexpected reserved word in a {name} file

Unexpected reserved word 'await' for react native

Unexpected reserved word 'await' in getting the session id

React JS Unexpected reserved word 'await'

Error in StackBlitz: 'Unexpected strict mode reserved word' trying to use async/await with subscription.toPromise()

Unexpected return of async/ await function

SyntaxError: Unexpected reserved word => prettier/third-party.js

Node.js application SyntaxError: Unexpected reserved word 'class'

Unexpected reserved word in for await - Would appreciate clarification o existing answer

async function run() { ^^^^^^^^ SyntaxError: Unexpected token function

React Native : Async and Await is a reserved word error inside onPress

Javascript: SyntaxError: await is only valid in async function

For loop - SyntaxError: await is only valid in async function

async arrow function SyntaxError: Unexpected token (

TypeScript: Unexpected reserved word

Jint "unexpected reserved word"

Uncaught SyntaxError: Unexpected identifier when async/await is present

Uncaught SyntaxError: await is only valid in async function in async function