Skip to content

Confusing error when using await in non-async function #9799

Description

@anishkny

Prettier 2.2.1
Playground link

--parser babel

Input:

function foo () {
  await bar();
}

Output:

SyntaxError: Unexpected token, expected ";" (2:9)
  1 | function foo () {
> 2 |   await bar();
    |         ^
  3 | }

Expected behavior:
Honestly, this error message makes no sense.

Perhaps a more relevant message would be:

SyntaxError: await is only valid in async function

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.scope:dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependency

    Fields

    No fields configured for Suggestion.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions