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

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

Closed
cspotcode opened this issue May 16, 2020 · 5 comments
Closed

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

cspotcode opened this issue May 16, 2020 · 5 comments

Comments

@cspotcode
Copy link

  • 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

@DerekNonGeneric
Copy link
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

@cspotcode
Copy link
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.

@DerekNonGeneric
Copy link
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

@cspotcode
Copy link
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.

@targos
Copy link
Member

targos commented May 16, 2020

#33437

targos added a commit to targos/node that referenced this issue Jul 14, 2020
@targos targos closed this as completed in 05539c1 Jul 14, 2020
MylesBorins pushed a commit that referenced this issue Jul 14, 2020
Fixes: #33435

PR-URL: #33437
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
MylesBorins pushed a commit that referenced this issue Jul 16, 2020
Fixes: #33435

PR-URL: #33437
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
cjihrig pushed a commit that referenced this issue Jul 23, 2020
Fixes: #33435

PR-URL: #33437
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
targos added a commit to targos/node that referenced this issue Sep 28, 2020
Fixes: nodejs#33435

PR-URL: nodejs#33437
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
addaleax pushed a commit that referenced this issue Sep 28, 2020
Fixes: #33435

PR-URL: #33437
Backport-PR-URL: #35394
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@targos targos removed their assignment Mar 1, 2022
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

Successfully merging a pull request may close this issue.

3 participants