-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
Entry points specified as absolute URLs fail to load #46009
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
Comments
If I'm reading this right, it seems like there's two distinct (altho related) items here:
|
The issue is that
It's not bug, it's a feature :) $ mkdir -p 'node_modules/file:/dev'
$ echo 'console.log("works")' > 'node_modules/file:/dev/null.js'
$ node file:///dev/null
node:internal/modules/cjs/loader:1042
throw err;
^
Error: Cannot find module '…/file:/dev/null'
at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
at Module._load (node:internal/modules/cjs/loader:885:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v19.3.0
$ node -e 'require("file:///dev/null")'
works
$ node --require file:///dev/null -e ';'
works
$ mv 'node_modules/file:' .
$ node file:///dev/null
works
$ node --require ./file:///dev/null -e ';'
works
Do we need a new feature or are we happy suggesting folks to do one of the following?
|
Hmm, yeah, I would expect anything provided via CLI to be a path, not a URL. I think we should handle it in SOME way, maybe even throw if the underlying utils can't handle a URL. |
Imo it should however be consistent with how |
the resolved path isn't invalid, you just don't happen to have a folder named |
I disagree, it seems much more logical that |
It isn't about `://` , `//` is only added to relative based urls (not blob
/ data / many protocols). `:` is perfectly valid in most file systems, and
empty filenames are supported in various ones, mostly through flat file
systems or remote file systems. `:` is more generally useful as it allows
simple string based injection without needing disk access for those flags.
…On Thu, Dec 29, 2022 at 12:16 PM Jordan Harband ***@***.***> wrote:
@aduh95 <https://github.com/aduh95> how can a relative path include "://"?
—
Reply to this email directly, view it on GitHub
<#46009 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABZJIZUTPQUU6TIQGS7J4TWPXIRVANCNFSM6AAAAAATLZ5M3U>
.
You are receiving this because you are on a team that was mentioned.Message
ID: ***@***.***>
|
Sure, but I couldn’t have a folder named There’s a distinction between allowable potential filename/path and existing potential filename/path. The resolution algorithm tries a bunch of ways to interpret the input, returning on the first option that succeeds or erroring if they all fail. We could add an additional method or two to the list of ways that it tries, to try to load the entry point if the input is interpreted as a URL that maps to an existing file:
|
What you're proposing is, depending on one's POV, either DWIM or second-guessing the user. I lean towards simplicity. Less room for surprise, confusion, and bugs - potentially of the security impacting kind. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Fixed by |
Version
19.3.0
Platform
Darwin Geoffreys-MacBook-Pro.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:08:47 PST 2022; root:xnu-8792.61.2~4/RELEASE_X86_64 x86_64
Subsystem
module, esm, process, cli
What steps will reproduce the bug?
With a checkout of the
node
repo at~/Sites/node
:Note the
/Users/geoffrey/file:/Users/geoffrey/Sites/node/test/fixtures/es-modules/mjs-file.mjs
constructed specifier. This doesn’t make sense.How often does it reproduce? Is there a required condition?
Every time.
What is the expected behavior?
Absolute file URLs should be allowable as program entry points.
What do you see instead?
Additional information
I understand per https://nodejs.org/api/cli.html#program-entry-point the entry point is parsed by the CommonJS resolver, even when it passes the criteria for being loaded by the ESM one; but it doesn’t make sense that either resolver would be constructing an invalid path.
It’s also counterintuitive that
file:///Users/geoffrey/Sites/node/test/fixtures/es-modules/mjs-file.mjs
should be acceptable input for--loader
and--import
but not as the main entry point. For example, all of these are valid:node --import file:///Users/geoffrey/Sites/node/test/fixtures/es-modules/mjs-file.mjs --eval ';'
node --loader file:///Users/geoffrey/Sites/node/test/fixtures/es-modules/mjs-file.mjs --eval ';'
node --import file:///Users/geoffrey/Sites/node/test/fixtures/es-modules/mjs-file.mjs ./Sites/node/test/fixtures/es-modules/mjs-file.mjs
node --loader file:///Users/geoffrey/Sites/node/test/fixtures/es-modules/mjs-file.mjs ./Sites/node/test/fixtures/es-modules/mjs-file.mjs
cc @aduh95 @JakobJingleheimer @nodejs/modules @nodejs/loaders
This came up because I was writing a test like this:
The solution was to change the second
fixtures.fileURL
tofixtures.path
; but this feels wrong.The text was updated successfully, but these errors were encountered: