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

Undocumented inability to put REPL in ES module context #32935

Closed
DerekNonGeneric opened this issue Apr 18, 2020 · 11 comments
Closed

Undocumented inability to put REPL in ES module context #32935

DerekNonGeneric opened this issue Apr 18, 2020 · 11 comments
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. experimental Issues and PRs related to experimental features. feature request Issues that request new features to be added to Node.js. repl Issues and PRs related to the REPL subsystem. stale v8 engine Issues and PRs related to the V8 dependency.

Comments

@DerekNonGeneric
Copy link
Contributor

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.

@GeoffreyBooth
Copy link
Member

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

@devsnek
Copy link
Member

devsnek commented Apr 18, 2020

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.

@GeoffreyBooth
Copy link
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.

@devsnek
Copy link
Member

devsnek commented Apr 19, 2020

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)

@GeoffreyBooth
Copy link
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.?

@devsnek
Copy link
Member

devsnek commented Apr 19, 2020

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

@devsnek devsnek transferred this issue from nodejs/modules Apr 20, 2020
@devsnek devsnek added esm Issues and PRs related to the ECMAScript Modules implementation. repl Issues and PRs related to the REPL subsystem. v8 engine Issues and PRs related to the V8 dependency. experimental Issues and PRs related to experimental features. feature request Issues that request new features to be added to Node.js. labels Apr 20, 2020
@BridgeAR
Copy link
Member

BridgeAR commented May 7, 2020

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.

@BridgeAR
Copy link
Member

BridgeAR commented May 7, 2020

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.

@DerekNonGeneric
Copy link
Contributor Author

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2022

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.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2022

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
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. experimental Issues and PRs related to experimental features. feature request Issues that request new features to be added to Node.js. repl Issues and PRs related to the REPL subsystem. stale v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

4 participants