You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is the non-function version of import (import {Foo} from "./bar.mjs";) supposed to work on the REPL? When I type that, I get a continuation prompt (...) as if I'd just typed the open brace of a function definition or conditional. (Node 8.11.1 LTS)
Does the fix @devsnek alluded to address this? Maybe it already works in a newer Node?
ETA: Nope, not in newer Node either -- I got 9.11.1 installed and now instead of the continuation prompt, I get
> import {Testing} from "./mod.mjs";
import {Testing} from "./mod.mjs";
^
SyntaxError: Unexpected token {
> import Testing from "./mod.mjs";
import Testing from "./mod.mjs";
^^^^^^^
SyntaxError: Unexpected identifier
Should I open a separate issue about parsing the REPL with the MJS / ESM loader, or is that addressed here?
@thw0rted that won't be supported any time soon.. the repl runs as a script parse goal. @bmeck has a proposal for tc39 for a "repl parse goal" somewhere which would allow it
Sorry, I'm a little new to Node. I guess what I'm really looking for is, can I use a .mjs from the REPL at all, and if so, what's the proper syntax? (And if not, is this the issue where that capability is going to get added?)
The reason for two changes is that there are separate code paths is that stdin from a file/pipe and stdin from a tty are separate code paths.
This change causes 5 existing tests to fail, many because they verify stack traces and the file name will show up there. And one because there is no cwd, so defensive code would need to be added.
https://gist.github.com/rubys/b79c692831b2a9a6dea4897c3d121f7b contains a test, which mostly passes when run individually, and mostly fails when run as a part of jstest. The failure in both cases is /Users/rubys/git/node/out/Release/node: bad option: --experimental-modules.
Once this is made to work, and once #21805 lands, then we will be in a position where the SyntaxError when parsing import statements will be passed to acorn and parsed. If it parses correctly as an import statement and if --experimental-repl-await is specified, then the equivalent await import() call can be substituted for the input.
there is a bunch of work that needs to be done to ModuleWrap and ContextifyScript first... I have the changes locally, just haven't finished them yet. (I realize I said that four months ago but it's actually close now 😓)
This is currently mostly working, in particular dynamic import can be used to import a file but you need to use a relative path to the folder's parent directory.
e.g. If you're in directory /foo/bar/baz then to import /foo/bar/baz/qux.js you need to import './baz/qux.js' rather than just ./qux.js even though ./baz/ is the directory you're already in.
Activity
devsnek commentedon Mar 24, 2018
i have this working in a branch, i'm just waiting on a few things before I open a pr
thw0rted commentedon Apr 24, 2018
Is the non-function version of import (
import {Foo} from "./bar.mjs";) supposed to work on the REPL? When I type that, I get a continuation prompt (...) as if I'd just typed the open brace of a function definition or conditional. (Node 8.11.1 LTS)Does the fix @devsnek alluded to address this? Maybe it already works in a newer Node?
ETA: Nope, not in newer Node either -- I got 9.11.1 installed and now instead of the continuation prompt, I get
Should I open a separate issue about parsing the REPL with the MJS / ESM loader, or is that addressed here?
devsnek commentedon Apr 24, 2018
@thw0rted that won't be supported any time soon.. the repl runs as a script parse goal. @bmeck has a proposal for tc39 for a "repl parse goal" somewhere which would allow it
thw0rted commentedon Apr 24, 2018
Sorry, I'm a little new to Node. I guess what I'm really looking for is, can I use a
.mjsfrom the REPL at all, and if so, what's the proper syntax? (And if not, is this the issue where that capability is going to get added?)devsnek commentedon Apr 24, 2018
@thw0rted no you cannot right now, but maybe in the future, and we're already tracking adding stuff like that 👍
rubys commentedon Jul 31, 2018
I've investigated this a bit, but I'm not quite ready to do a pull request.
This can be made to work with the following patch:
The reason for two changes is that there are separate code paths is that stdin from a file/pipe and stdin from a tty are separate code paths.
This change causes 5 existing tests to fail, many because they verify stack traces and the file name will show up there. And one because there is no cwd, so defensive code would need to be added.
https://gist.github.com/rubys/b79c692831b2a9a6dea4897c3d121f7b contains a test, which mostly passes when run individually, and mostly fails when run as a part of jstest. The failure in both cases is
/Users/rubys/git/node/out/Release/node: bad option: --experimental-modules.Once this is made to work, and once #21805 lands, then we will be in a position where the
SyntaxErrorwhen parsing import statements will be passed to acorn and parsed. If it parses correctly as an import statement and if--experimental-repl-awaitis specified, then the equivalentawait import()call can be substituted for the input.devsnek commentedon Jul 31, 2018
there is a bunch of work that needs to be done to ModuleWrap and ContextifyScript first... I have the changes locally, just haven't finished them yet. (I realize I said that four months ago but it's actually close now 😓)
rubys commentedon Jul 31, 2018
@devsnek anything I can do to help?
devsnek commentedon Jul 31, 2018
@rubys I'll open a PR with my current changes tomorrow and see what people think
rubys commentedon Aug 17, 2018
@devsnek ping?
devsnek commentedon Aug 17, 2018
whoops i completely forgot about this... rebasing branch now and then i'll throw up a pr
Jamesernator commentedon Nov 6, 2019
This is currently mostly working, in particular dynamic import can be used to import a file but you need to use a relative path to the folder's parent directory.
e.g. If you're in directory
/foo/bar/bazthen to import/foo/bar/baz/qux.jsyou need to import'./baz/qux.js'rather than just./qux.jseven though./baz/is the directory you're already in.devsnek commentedon Nov 6, 2019
The fix is basically to set the referrer to
process.cwd() + '/repl'.repl: fix referrer for dynamic import
repl: fix referrer for dynamic import
repl: fix referrer for dynamic import
repl: fix referrer for dynamic import