Skip to content

Undocumented inability to put REPL in ES module context #32935

Description

@DerekNonGeneric

There does not appear to be a way to put the REPL in ES module context.

The closest you'll get to it seems to be by running:

  1. node --experimental-repl-await
  2. await import('./foo.mjs')

Give it a try and you'll see that evaluating import.meta throws this error:

import.meta
       ^^^^

Uncaught SyntaxError: Cannot use 'import.meta' outside a module

I'd like this issue to discuss whether or not this limitation is presently documented somewhere or should be illuminated in https://nodejs.org/api/esm.html or elsewhere.

Note: this issue isn't about executing code with --eval using the --input-type=module flag.

Activity

  1. GeoffreyBooth commented on Apr 18, 2020

    @GeoffreyBooth
    Member

    cc @devsnek, what's the latest on that "REPL" parse goal?

  2. devsnek commented on Apr 18, 2020

    @devsnek
    Member

    if you mean the tc39 proposal, it's not doing anything right now. if you mean the v8 debug feature, I think they're in user feedback mode atm, not actively making anything.

  3. GeoffreyBooth commented on Apr 18, 2020

    @GeoffreyBooth
    Member

    So I think where we left off with this was that when/if the REPL parse goal shipped, our REPL would use that. But if that's not advancing, should we discuss alternatives?

    One option that comes to mind is to just extend --input-type to apply to the REPL. But I don't know how that would work in practice; I would think that static import and export statements would throw, for example. And since import() is already supported in Script/CommonJS, such a REPL mode wouldn't be that different than what we have now.

    I tried typing import.meta into the Chrome console and I got the same Uncaught SyntaxError: Cannot use 'import.meta' outside a module error, so I guess that's not supported there either.

  4. devsnek commented on Apr 19, 2020

    @devsnek
    Member

    In the short term I can try to look into enabling import declarations and import.meta in V8 replMode. I don't think --input-type should have any effect on the repl, it doesn't really make sense to call it a script or a module or anything like that. We will have to overhaul our repl in node to take advantage of replMode though (cc @BridgeAR)

  5. GeoffreyBooth commented on Apr 19, 2020

    @GeoffreyBooth
    Member

    So V8 replMode is basically the “REPL parse goal” I remember you describing, where it tries to support everything at once? import statements, redeclaring const, etc.?

  6. devsnek commented on Apr 19, 2020

    @devsnek
    Member

    @GeoffreyBooth i don't know the exact plans of the v8 team, i posted in v8:6903 so we'll see what happens.

  7. transferred this issue fromnodejs/moduleson Apr 20, 2020
  8. added
    esmIssues and PRs related to the ECMAScript Modules implementation.
    replIssues and PRs related to the REPL subsystem.
    v8 engineIssues and PRs related to the V8 dependency.
    experimentalIssues and PRs related to experimental features.
    feature requestIssues requesting new Node.js features.
    on Apr 20, 2020
  9. BridgeAR commented on May 7, 2020

    @BridgeAR
    Member

    The replMode allows to reassign let statements gracefully. We'll have to implement some parts in vm first to access that part though (at least that's how it seemed when I last checked).

    It is likely that the replMode will receive further changes later on but that's all that is included so far.

  10. BridgeAR commented on May 7, 2020

    @BridgeAR
    Member

    Top level await will be available as soon as V8 supports that (acorn must also support it but that should not take too long afterwards). It's independent from the replMode.

  11. DerekNonGeneric commented on Jun 12, 2020

    @DerekNonGeneric
    ContributorAuthor

    Should we document this inability in the meantime? Hope to tackle this issue unless it's tracking something else.

  12. github-actions commented on Mar 8, 2022

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

  13. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Mar 8, 2022
  14. github-actions commented on Apr 8, 2022

    @github-actions
    Contributor

    There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

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

    esmIssues and PRs related to the ECMAScript Modules implementation.experimentalIssues and PRs related to experimental features.feature requestIssues requesting new Node.js features.replIssues and PRs related to the REPL subsystem.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions