deno: es module imports in repl don't work
When in the Deno REPL and executing:
import { env } from "deno";
The output is:
SyntaxError: Unexpected token {
Probably related to #1158
Executing: deno -v on the commandline returns:
deno: 0.2.1
v8: 7.1.302.4
typescript: 3.2.1
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 18 (14 by maintainers)
That isn’t a TypeScript feature persay…
importis valid ES6 syntax. But imports in general don’t work in the REPL, which is a known limitation. Native ESM support is being worked on (tracked by #975) and it should flow through to the REPL eventually.The
denonamespace though is available in the global scope, soconst { env } = deno;would work for now.Typescript isn’t supported in the repl yet, #1158.
if you’re claiming some new improved runtime, just seems lazy not to support imports in the repl so that they can be identical to scripts when run. dynamic reports requires non-zero time from end users when trying/converting examples, developing scripts etc. and my money is that adoption of your project will suffer for it
Fixed in https://github.com/denoland/deno/pull/7784; dynamic imports is the way to go when importing in REPL
If this is impossible… Perhaps import could be translated to import () prior to evaluation e.g. with regex. Or, perhaps less drastically, but less usefully, the repl could suggest import() syntax be used upon seeing this error (and regex match).
You have the wrong idea here: neither me nor @caspervonb are maintainers, we are contributors.
Your behaviour has been hostile, and you have been violating the CoC:
and other points in the CoC.
Well the repl is constantly getting improved, alongside the rest of the codebase. just some things have higher priority than the others. The repl is for quick debugging & trying things out. Having modules in the form of dynamic modules over static modules makes sense in the environment of a repl, where things are dynamic and not statically known, so no module can be made for the running repl, thus not allowing static imports. I am not sure if this can be changed or not, but if it can, it definitively is not a simple task, else it would have been done so from the beginning. Adding this functionality is not a priority.