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

Repl has "Unexpected token ','" when both await and second argument to dynamic import are used #47463

Closed
Jamesernator opened this issue Apr 7, 2023 · 4 comments
Labels
repl Issues and PRs related to the REPL subsystem.

Comments

@Jamesernator
Copy link

Version

v19.8.1

Platform

Linux 5.19.0-38-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

repl

What steps will reproduce the bug?

Try in the repl:

> let packageJSON = await import("./package.json", { assert: { type: "json" } })

Uncaught SyntaxError: 
let packageJSON = await import("./package.json", { assert: { type: "json" } })
                                               ^

Unexpected token ','

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).

What do you see instead?

The error:

Uncaught SyntaxError: 
let packageJSON = await import("./package.json", { assert: { type: "json" } })
                                               ^

Unexpected token ','

Additional information

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.

@VoltrexKeyva VoltrexKeyva added the repl Issues and PRs related to the REPL subsystem. label Apr 8, 2023
@aduh95
Copy link
Contributor

aduh95 commented Apr 13, 2023

This should parse as it is perfectly valid syntax

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.

@029A-h
Copy link

029A-h commented Dec 6, 2024

Acorn 8.14.0 has dynamic import attributes support (acornjs/acorn#1332).
Can we test and bump the version now?

@richardlau
Copy link
Member

Acorn 8.14.0 has dynamic import attributes support (acornjs/acorn#1332). Can we test and bump the version now?

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
Copy link

029A-h commented 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.

@aduh95 aduh95 closed this as completed Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

No branches or pull requests

5 participants