Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

top-level await not working #199

Closed
dnalborczyk opened this issue Dec 23, 2017 · 5 comments
Closed

top-level await not working #199

dnalborczyk opened this issue Dec 23, 2017 · 5 comments
Labels

Comments

@dnalborczyk
Copy link
Contributor

top-level await seems to be not working. not sure if that is a regression (never tried it, until now).

node 9.3.0, std/esm v0.18.0

repro steps:

esmrc:

{
  "await": true
}

index.js:

await 1;

cli:

node --require @std/esm index.js

error:

await 1;
^^^^^

SyntaxError: await is only valid in async function
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:152:10)
    at Module._compile (module.js:624:28)
    at Object.Module._extensions..js (module.js:671:10)
@jdalton
Copy link
Member

jdalton commented Dec 23, 2017

It looks like I'm only enabling top-level await for ESM. So if you're using the defaults you'd want to make that an index.mjs. I'll expand it to supporting both CJS and ESM though.

@dnalborczyk
Copy link
Contributor Author

@jdalton I had a suspicion, since the docs are mentioning

A boolean to support top-level await in the main ES module.

but I thought, if it's not meant to work in CJS, I would have suggested to change the wording to emphasize that the "await" flag only works in ES modules.

Anyhow, I tried the above with ESM (default):

index.mjs

await 1;

esmrc:

{
  "await": true
}

cli:

node --require @std/esm index.mjs

... as well as:

index.js

await 1;
{
  "esm": "js",
  "await": true
}

cli:

node --require @std/esm index.js

and both are still failing. :/

@jdalton
Copy link
Member

jdalton commented Dec 24, 2017

Patched 5743e31 and 82e88cc.

@jdalton jdalton added bug and removed question labels Dec 24, 2017
@dnalborczyk
Copy link
Contributor Author

just tried top-level await with ESM (default mjs and explicit js) and CJS mode on lastest master - and needless to say, both work now! 😃

Thanks for your amazing work @jdalton !!

dnalborczyk added a commit to dnalborczyk/esm that referenced this issue Dec 28, 2017
follow up from: standard-things#199

clarification for top-level _await_ support in ESM and CJS, also noting that Node v7.6+ is required.
@jdalton
Copy link
Member

jdalton commented Jan 6, 2018

@std/esm v0.19.0 is released 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants