question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use keyword 'await' outside an async function

See original GitHub issue

Bug report

What is the current behavior?

ERROR in ./app/src/ui/charts/export/png.ts 190:11
Module parse failed: Cannot use keyword 'await' outside an async function (190:11)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|   });
|   toBlob = async () => {
>     return await this.toCanvas().then(canvasToBlob);
|   };
| }

If the current behavior is a bug, please provide the steps to reproduce.

I believe it’s an issue with a class property which is an async function. Webpack is not able to handle the case below:

class A {
  m = async () => {
    return await Promise.resolve();
  };
}

What is the expected behavior?

I believe webpack should be able to handle this use case.

Other relevant information: webpack version: 5.36.0 Node.js version: 15.11.0 Operating System: MacOS 10.15.7

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
alexander-akaitcommented, Apr 29, 2021
1reaction
pbadenskicommented, Apr 29, 2021

Awesome turnaround time - thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using await outside of an async function - Stack Overflow
This I hoped would await to results, so I can use inLobby to conditionally run countPlayer , however I received a typeerror with...
Read more >
How to use await outside of an async function in JavaScript
There are multiple ways to use the `await` operator outside of an `async` function - use a Node.js version higher than `16.12.0`, load...
Read more >
How to use await outside of an async function in JavaScript
First, the important thing to note down here is that there is no direct way possible to use await outside of the async-function,...
Read more >
Cannot use keyword await outside an async function <script ...
Checklist I have tried restarting my IDE and the issue persists. I have read the FAQ and my problem is not listed.
Read more >
Module parse failed: Cannot use keyword 'await' outside an ...
I set my tsconfig.json to use "es2017" for await. It's still not compiling. Have no idea how to configure Web3Modal to a Button....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found