Skip to content

"await is only valid in async function" when trying to use await in a for loop with TLA support #32708

@serge1peshcoff

Description

@serge1peshcoff
  • Version: 12.14.1
  • Platform: macOS 10.14.x
  • Subsystem:

What steps will reproduce the bug?

I run node with TLA support flag, I don't get the error if I do await on a top-level, but I do get the error if I do it in a for loop.

How often does it reproduce? Is there a required condition?

$ node --experimental-repl-await
Welcome to Node.js v12.8.1.
Type ".help" for more information.
> const timeout = delay => new Promise((res) => setTimeout(res, delay));
undefined
> timeout(1000).then(() => console.log('aaa'))
Promise { <pending> }
> aaa // this is displayed after 1 second, so it's fine
> await timeout(1000);
undefined // this is executed after 1 second, so it's also fine
> for (const i of [1, 2, 3]) {
... await timeout(1000);
Thrown:
await timeout(1000);
^^^^^

SyntaxError: await is only valid in async function
>

What is the expected behavior?

No error.

What do you see instead?

Error, see above.

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions