-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Improve "Cannot find module" error #26588
Comments
Is this what you're looking for? #25690 |
It sounds pretty similar. In the example there, the stack trace is In my case, neither actual missing file nor the package.json [section] that refers to it are mentioned in the stacktrace. I decided to build the latest master (commit 06879aa) which seems to include #25690. Repeating my test, the traceback is slightly different but still doesn't seem to mention the missing file: After removing
So I think the answer is no, that's not quite what I'm looking for, unless I've misunderstood something :-( |
I see what you mean. Unfortunately, I'm not sure we can efficiently add the information you're looking for to the error. For example, in your original post, you remove a file from |
In this specific case, the loader is presumably looking for the file /a/b/c/node_modules/foo/dist/entry.js Then the I accept that there's probably other edge cases where you might have the same package installed in 2 locations that will be searched and they're both broken in different ways. I don't know what the current behaviour is but my guess would be that it will bork at the first broken package it encounters once the package.json has been parsed? In which case showing the specific error for that broken package would be fine from my point of view. I understand this is going to be low priority, if indeed it is worth considering at all, and I am no expert in JS, let alone the internals of the node package loader, so I am happy to defer to your judgement on whether this is worth persuing further. :) |
That's not necessarily true. Each
Not necessarily true either. Sorry, I know the loader has a ton of edge cases in it. |
Oh well, thanks for taking the time to explain this a bit more anyway. Happy for you to close this as it seems like it's probably not a feasible benefit:cost ratio. |
I had a look at this again and I opened a PR to improve the situation: |
We currently ignore invalid `main` entries in package.json files. This does not seem to be very user friendly as it's certainly an error if the `main` entry is not a valid file name. So instead of trying to resolve the file otherwise, throw an error immediately to improve the user experience. Fixes: nodejs#26588
@BridgeAR thanks so much for implementing this! I can't say I look forward to seeing the new error in production but if I do I will be much happier than before! :D |
Is your feature request related to a problem? Please describe.
While trying to debug an issue, I found the error message from node to be slightly misleading and/or not as useful as it could have been.
Here is a toy example of the issue:
We have a package called "foo". It consists of a package.json and dist/entry.js:
package.json:
dist/entry.js
We can import this package, everything is good:
The improvement comes when we delete the entrypoint for our foo module. In my real-world case, this was done by an overzealous package-trimming routing in a CI pipeline, but I guess there are probably other ways it can occur. It's clearly the user's 'fault', but the error message isn't super obvious:
The issue here is that the error message
Error: Cannot find module 'foo'
isn't super helpful, because you have a look innode_modules
, and you see a directoryfoo/
, and you see that directory containspackage.json
. Maybe you also see it contains asrc/
dir, atests/
dir, and all sorts of other stuff. In my case, this led me to believe the error was that the node interpreter was somehow configured not to look in the local node_modules directory, and led to a fair bit of wild-goose chasing.Describe the solution you'd like
It would be better if the error message directly referred to the missing [main/entry-point]file. E.g. if the error was something like:
it would be immediately obvious why node can't load the module.
Describe alternatives you've considered
The obvious alternative is to do nothing, which would maintain the current error messaging and behaviour.
The text was updated successfully, but these errors were encountered: