-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
module: fix error message for not found #53110
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
521f4a2
to
c124e57
Compare
What bug does this fix? Please add a description explaining your intent with this PR and why it’s the best solution of alternatives you considered. |
@GeoffreyBooth Updated. |
mkdir repro && cd repro
mkdir -p node_modules/fs
echo 'export let readdir' > node_modules/fs/promisesxxx.mjs
echo '{"name":"fs","exports":{"./promisesxxx":"./promisesxxx.mjs"}}' > node_modules/fs/package.json
node --input-type=module -e 'import {readdir} from "fs/promisesxxx"'
cd .. && rm -r repro You can see that the import doesn't raise any error. |
{ | ||
code: 'ERR_MODULE_NOT_FOUND', | ||
name: 'Error', | ||
message: /Cannot find package 'fs\/promisesx'/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct, the missing package is fs
, not fs/promisesx
. What you could do is to add the complete specifier – either as Cannot find package 'fs' imported from … while trying to resolve 'fs/promisesx'
, or as an additional property on the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO for the end-users, Cannot find package 'fs'
will not hint them that fs/promisesx
is the not-found package/specifier.
But I'm not an expert on this, so IDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to the suggestion by @aduh95 as this giving more context.
For builtins, it might even be worth having a different error message, that is builtin specific:
Unable to import builtin module 'fs/promisesx'
.
And if we're doing wishful thinking, would be amazing to see levenshtein distance searching:
Unable to import builtin module 'fs/promisesx', did you mean 'fs/promises'
?.
Such suggestion error messages could in theory even apply to node_modules packages lookups and exports as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion error messages seem like a good idea to have in general :-)
The key point is should report the full package name in error message. It is not related to native module or user-land module. |
The full package name is |
When I written module path with a typo:
The error message tell me cannot find package 'fs'.
Actually the
fs
is a native module, the package should be a full name. This update try to fix it.