You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Repl has "Unexpected token ','" when both await and second argument to dynamic import are used #47463
How often does it reproduce? Is there a required condition?
This happens consistently, curiously the features seem to work separately but not together:
// Both of these are fine:
> let p = import("./package.json", { assert: { type: "json" } });
> let p = await import("./package.json"); // Runtime error due to missing second arg
What is the expected behavior? Why is that the expected behavior?
This should parse as it is perfectly valid syntax (and it works without await).
There was recently changes to the import assertions proposal to change assert to with (along with changes to affect runtime), but even with that the parsing of the above would be the same anyway.
It's not valid syntax according to the current ES spec – because the Import Attributes proposal is stage 3 only.
it works without await
The reason for this lack of consistency is because when you pass a string that contains await, it goes through Acorn, and I think Acorn only supports stage 4 syntax.
Not sure what to do about that, I guess if you are using await on the REPL, you have to accept Acorn limitations, I don't think there's a way around that.
You are correct. I tested dynamic imports with attributes on Node.js 23.3.0, and everything works as expected. I suggest closing this issue. Thank you for your cooperation.
Activity
aduh95 commentedon Apr 13, 2023
It's not valid syntax according to the current ES spec – because the Import Attributes proposal is stage 3 only.
The reason for this lack of consistency is because when you pass a string that contains
await, it goes through Acorn, and I think Acorn only supports stage 4 syntax.Not sure what to do about that, I guess if you are using
awaiton the REPL, you have to accept Acorn limitations, I don't think there's a way around that.029A-h commentedon Dec 6, 2024
Acorn 8.14.0 has dynamic import attributes support (acornjs/acorn#1332).
Can we test and bump the version now?
richardlau commentedon Dec 6, 2024
Bumped in #55699 and went out in Node.js 23.2.0 and 22.12.0. It has watch labels for 20 and 18 so should eventually make its way there too.
029A-h commentedon Dec 8, 2024
You are correct. I tested dynamic imports with attributes on Node.js 23.3.0, and everything works as expected. I suggest closing this issue. Thank you for your cooperation.