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

Can't Import Ecmascript Modules via REPL #2629

Closed
Lonniebiz opened this issue Jul 10, 2019 · 4 comments
Closed

Can't Import Ecmascript Modules via REPL #2629

Lonniebiz opened this issue Jul 10, 2019 · 4 comments

Comments

@Lonniebiz
Copy link

Lonniebiz commented Jul 10, 2019

deno: 0.10.0
v8: 7.7.37
typescript: 3.5.1

When you try to import an ecmascript module using the REPL, you get an Uncaught SyntaxError:

> import Drash from "https://deno.land/x/drash@v0.8.6/mod.ts";
error: Uncaught SyntaxError: Unexpected identifier
► <unknown>:1:8
    at evaluate (js/repl.ts:87:34)
    at replLoop (js/repl.ts:145:13)

Node.js allows CommonJS module loading using their REPL, but I'm unable to import ES modules there either: https://stackoverflow.com/questions/56963708/.

@kt3k
Copy link
Member

kt3k commented Jul 10, 2019

(duplicate of #1285)

@kevinkassimo
Copy link
Contributor

kevinkassimo commented Jul 10, 2019

Dup of #1285. This is expected. ES Module is slightly different from require as resolution is asynchronous, and could only exist in module level (e.g. in an independent file). Also see https://medium.com/the-node-js-collection/an-update-on-es6-modules-in-node-js-42c958b890c
REPL works differently: it takes your code and eval under a context, without creating new modules. So static import statements are unexpected.

What you want is actually the dynamic import. I think Ryan has a WIP implementation for it, so it should be available soon. See https://v8.dev/features/dynamic-import

@kevinkassimo
Copy link
Contributor

I think currently if we really want to do this, there are only 2 solutions:

  1. Fake one: parse import statements and convert to dynamic import secretly. Also requires top level await support.
  2. Concatenate past commands and join them into a script and eval from beginning every single time. I remember this is similar to what ts-node is doing with their REPL.
    I believe neither of these solutions are perfect, and should not be prioritized due to other more important work to complete

@Lonniebiz
Copy link
Author

@kevinkassimo : I should have thought of that!

https://stackoverflow.com/a/56966774/217867

@ry ry closed this as completed Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants