Support top-level-await #997
Comments
I have the same issue, top level await doesn't want to compile. |
This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label |
This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit. |
Still an issue |
Does the issue persists on 4.5.1? |
Yes, 4.5.1: > Error! 'await' is only allowed within async functions (45:12)
|
That's strange, @jesec any clue? |
I will share a MVP example soon here |
Top level await is not allowed in any of the current Node versions supported by pkg. This is expected behavior. |
@jesec node 13.3+ should allow that, just needs a flag |
Need |
I have edited my comment, btw I think that we already have versions that support it we should understand why it is not working, maybe node options are not correctly applied on start? |
This should be treated as a feature request. We can’t support every experimental Node feature out there. |
I think we should add it here? Line 56 in 6deb812
|
I've shared the (trunkated) settings I've tried to use. But even with |
// a.js
console.log(await Promise.resolve(42)); doesn't work with nodejs either the and this is the expected behavior. top level await is not supported yet in nodejs by default unless you use the --harmony-top-level-await flag) $ node a.js
console.log(await Promise.resolve(42));
^^^^^
SyntaxError: missing ) after argument list a simple workaround is to wrap the async call into an async function (async ()=>{
console.log(await Promise.resolve(42));
})(); |
Not correct, it is supported starting from nodejs 13.3+ but requires a flag, see my comment #997 (comment) |
@robertsLando how should I run pkg then, I can't seem to get it to work. |
I'm not 100% sure but you may need to add that option on fabricator.js @Dunky13, I have linked you the line in my prev comment |
Features are hidden behind flags for a reason. |
That I understand, but as stated in #997 (comment) I tried enabling these flags in |
A flag is not required when using await on an import statement, ie: "await import('node-fetch')". This bug is preventing me from building an application that uses the above syntax to conditionally import a library in code meant to run in either browser or node. This is distinct from using await in general, which I didn't even know there was a flag to enable before seeing this thread. Edit: There appear to be other issues as well causing 'Failed to make bytecode' when using ES6 module imports after temporarily disabling the above syntax. |
I get the same error:
When using the node16 target, of which top level await is enabled by default. |
Yup, I am also getting the exact same error. |
top-level await supported since 2020-08-11 in node js 14.8 without any flag as a default behavior. |
This is still an issue and no longer an experimental feature hidden behind a flag. |
Having this issue as well. |
I'm having this issue as well. |
@jesec I think this could be fixed once we add support for es modules parsing |
is there a road map / ETA for es modules parsing? |
I created a test here: #1323 and I tried to fix it but I have no idea about the changes needed to make the support of them. The problem is that actually we are using npm |
I am also having this issue |
The text was updated successfully, but these errors were encountered: