镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

@Jamesernator

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.

Activity

  1. added
    replIssues and PRs related to the REPL subsystem.
    on Apr 8, 2023
  2. aduh95 commented on Apr 13, 2023

    @aduh95
    Contributor

    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.

  3. 029A-h commented on Dec 6, 2024

    @029A-h

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

  4. richardlau commented on Dec 6, 2024

    @richardlau
    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.

  5. 029A-h commented on Dec 8, 2024

    @029A-h

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions