Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm.runInThisContext fails with top-level await #40898

Closed
n-riesco opened this issue Nov 20, 2021 · 2 comments
Closed

vm.runInThisContext fails with top-level await #40898

n-riesco opened this issue Nov 20, 2021 · 2 comments

Comments

@n-riesco
Copy link

Version

v16.13.0

Platform

Linux 176bea3b1763 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64 GNU/Linux

Subsystem

vm

What steps will reproduce the bug?

$ node
Welcome to Node.js v16.13.0.
Type ".help" for more information.
> vm.runInThisContext("await 42")
evalmachine.<anonymous>:1
await 42
^^^^^

Uncaught:
SyntaxError: await is only valid in async functions and the top level bodies of modules
> 

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

always

What is the expected behavior?

Some output as running await 42.

What do you see instead?

$ node
Welcome to Node.js v16.13.0.
Type ".help" for more information.
> await 42
42
> 

Additional information

No response

@devsnek
Copy link
Member

devsnek commented Nov 20, 2021

vm.runInThisContext runs a script and therefore does not support top level await. if you want to use that you'll need to use the experimental vm.Module api. the repl is just transpiling code with top level await into async functions.

@devsnek devsnek closed this as completed Nov 20, 2021
@n-riesco
Copy link
Author

@devsnek Do you know if V8 has plans for this? eval("await 42") also fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants