Skip to content

node --loader for REPL (without entrypoint) does not execute loader #33435

Description

@cspotcode
  • Version: 14.2.0
  • Platform: Ubuntu 16.04.6
  • Subsystem: ESM loader hooks, REPL

What steps will reproduce the bug?

cat 'console.log("hooks executing")' > hooks.mjs
node --loader ./hooks.mjs
# At the REPL prompt:
> import("http://example.com/foo")

The message "hooks executing" is never written to stdout, indicating that hooks.mjs is never executed, even though the ESM resolve hook should be invoked to handle our import() call.

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

When launching the node REPL with --loader flag, the loader hooks are executed.

What do you see instead?

Loader hook file is not executed.

Additional information

Activity

  1. DerekNonGeneric commented on May 16, 2020

    @DerekNonGeneric
    Contributor

    [...] the ESM resolve hook should be invoked to handle our import() call

    The REPL isn't actually in ES module context. See #32935 for details.

    /cc @devsnek

  2. cspotcode commented on May 16, 2020

    @cspotcode
    Author

    @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.

  3. DerekNonGeneric commented on May 16, 2020

    @DerekNonGeneric
    Contributor

    @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 import syntax 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.

    /cc @BridgeAR @GeoffreyBooth

  4. cspotcode commented on May 16, 2020

    @cspotcode
    Author

    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.

  5. self-assigned this
    on May 16, 2020
  6. targos commented on May 16, 2020

    @targos
    Member
  7. removed their assignment
    on Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions