Repository navigation
node --loader for REPL (without entrypoint) does not execute loader #33435
Description
Activity
@DerekNonGeneric
import()calls made from the REPL should be passed through custom loader hooks, correct?Calling
import('./foo.mjs')from the REPL does work. So I believe that loader hooks should be invoked in that case. But based on the reproduction posted in this issue, they are not executed.@DerekNonGeneric import() calls made from the REPL should be passed through custom loader hooks, correct?
That would seem plausible seeing as how it's using the same ESM loader.
Since
importsyntax in REPL context does not presently have feature parity w/ ES module context, I wouldn't consider this issue to be a bug per se, but more of a case of mistaken expectations. Perhaps this issue would have been better suited as a feature request? We'll have to see if others who are more familiar w/ the REPL have further insight.To clarify my use-case, I don't care if the REPL has feature parity with ES module context. I expect the REPL to run as CommonJS, though if in the future it runs as ESM, that will also be ok. If
import()s in both CommonJS and ESM files pass through loader hooks, then the REPL will intuitively be expected to do the same, in the absence of any documentation, errors, or warnings to the contrary.I've implemented a loader hook and published it to npm. When people try to use it, and node's loader behavior is confusing or seems to violate node's documentation, then they'll file bug reports with me. I'll redirect them to https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_experimental_loaders, which hopefully will be updated as needed to clarify node's REPL behavior and the caveats with loader hooks.
I understand that all of this is experimental.
- Reacted by Derek Lewis
- added a commit that references this issue
on Jul 14, 2020 - added 2 commits that reference this issue
on Jul 14, 2020 - added a commit that references this issue
on Jul 23, 2020 - added a commit that references this issue
on Sep 28, 2020 - added a commit that references this issue
on May 22, 2026
What steps will reproduce the bug?
The message "hooks executing" is never written to stdout, indicating that
hooks.mjsis never executed, even though the ESM resolve hook should be invoked to handle ourimport()call.How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
When launching the node REPL with
--loaderflag, the loader hooks are executed.What do you see instead?
Loader hook file is not executed.
Additional information