-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
loaders: super confusing "expected string but got instance of string" #49576
Comments
I don't know if you miss it, or if you are just not talking about it, but the error message says it expected a URL string. |
Well, I did see that, but I was thinking that my code was only ever returning a stringified URL object, and forgot that the |
PR-URL: nodejs#49580 Fixes: nodejs#49576 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
Version
21.0.0-pre, 20.6.0, 18.17.1
Platform
Darwin moxy.lan 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64
Subsystem
loaders, modules, errors
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
If the resolve() or load() function in a loader accidentally returns a shortCircuit response for a node builtin, or any other string which cannot be parsed as a URL.
What is the expected behavior? Why is that the expected behavior?
The error should indicate that the expected value should be a URL-parseable string, but instead got a string that could not be parsed.
What do you see instead?
The error is very confusing, indicating that a string was expected, but instead an instance of string was returned. In fact,
'events' instanceof String
is clearly false, so this is not really an "instance of String".Additional information
Maybe in cases like these, the string itself should be included on the Error object or in the message. It would've been immediately clear to me that
'events'
, while being a string, is not a valid URL. However, the wording of the error message had me thinking I'd mistakenly donenew String()
somewhere instead of casting to a string primitive.At the very least, the "instance of" wording should only be included if
typeof value === 'object' && value !== null
, because primitives are notinstanceof
anything.The text was updated successfully, but these errors were encountered: