What causes this error?
async keywords might not seem like they’re important and that’s you making a big mistake. The main cause of the error is the use of
await in a function that is not declared as asynchronous using the
How to solve this error?
The only way to solve the error is to either remove the
await statement or make the function asynchronous. Based on how you’ve written your code, you might need to work a bit harder to find the exact method that needs to be asynchronous.
One very important thing to keep in mind is the level of
async that you’re using. Just because a function has been declared asynchronous, that doesn’t mean any functions declared inside will also be asynchronous by default. You’ll have to specify
async explicitly for each level unless you’re declaring a top level
If you’re trying to use
async at the top level, make sure that the
type attribute has been set as
module in the
package.json file before proceeding. Alternatively, you can also attribute a
script tag in your browser.
Last but not least, if you’re in a browser environment, set the
type attribute to
module inside your
script tag to be able to use
async for the entire imported file.