-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
esm: better error message using commonjs hint #31906
Conversation
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.
Error: Cannot find module /home/travis/build/nodejs/node/test/common/fixures imported from /home/travis/build/nodejs/node/
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:71:11)
at Loader.resolve (internal/modules/esm/loader.js:85:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:191:28)
at Loader.import (internal/modules/esm/loader.js:166:28)
at internal/process/esm_loader.js:69:31
at Object.initializeLoader (internal/process/esm_loader.js:73:5)
at runMainESM (internal/modules/run_main.js:45:20)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:68:5)
at internal/main/run_main_module.js:17:47 {
code: 'ERR_MODULE_NOT_FOUND'
}
it will appear Error: Cannot find module /no/exist.js imported from xxx/xxx/index.js I think we can't directly use commjs module loader |
d1d88cf
to
e37665c
Compare
Thanks @himself65 , there was a typo in the module path I was requiring. I can't reproduce the error message you posted in your last comment. |
8ba1cc8
to
116a580
Compare
116a580
to
e9b1fc6
Compare
e9b1fc6
to
31ab988
Compare
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.
This is looking great - thanks @dnlup for your work and apologies for the delayed review.
I'd love to get this merged in soon if you can take a look at the feedback.
31ab988
to
2d1faef
Compare
@guybedford Sorry for the late come back. I tried to implement the suggestions you made. I had problems finding a way to test the error message on a bare specifier. I think I would have to add a PS: I did test it manually though |
if it helps, we used to have this: https://github.com/nodejs/node/blob/v11.x/lib/internal/modules/esm/default_resolve.js#L39. |
a1b7331
to
99cacc5
Compare
I added two tests to check the behavior suggested by @guybedford and rebased against master. |
Tests are failing because I am getting a different output on |
Yes it seems like it's just an extra line needed there now. This is looking really nice, that the suggestion is exactly what the user should type is great! Let me know when this is ready for review. |
6901254
to
f661d26
Compare
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.
This is awesome work and LGTM.
This is going to be a huge help for lots of folks, thanks for putting in the time to get this working.
Thanks, everyone for the review and the feedback. I am trying to fix the errors on Windows then this should be ready. Sorry if it's taking a long time. |
e7dbfaa
to
2918b22
Compare
Run CommonJS resolver only if `error.code` is ERR_MODULE_NOT_FOUND. Avoid using absolute paths in hint by: * using a relative (to the parent) path if the specifier is a relative path * using a `pkg/x.js` format if the specifier is bare (e.g. `pkg/x`)
2918b22
to
6511767
Compare
I think we are good to go, could you take another look? |
Just running CI, then lets get this merged asap. |
Run CommonJS resolver only if `error.code` is ERR_MODULE_NOT_FOUND. Avoid using absolute paths in hint by: * using a parent-relative path if the specifier is a relative path * using a `pkg/x.js` format if the specifier is bare (e.g. `pkg/x`) PR-URL: #31906 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Thank you all for your help! |
Run CommonJS resolver only if `error.code` is ERR_MODULE_NOT_FOUND. Avoid using absolute paths in hint by: * using a parent-relative path if the specifier is a relative path * using a `pkg/x.js` format if the specifier is bare (e.g. `pkg/x`) PR-URL: #31906 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Should we backport this to v12.x-staging? Two tests fail when I apply it. |
@targos could you post a link of the failing build? I am not sure I found the right one. |
There's no failing build. I did Here's the output:
|
@targos thanks for looking into this... it seems like the difference here is the experimental modules warning on the first line. Adding this line into the output fixture for the backport should fix this and just does seem like a necessary process for any modules messages diffs while we have this difference between the versions. |
Aaaah of course. I didn't realize it was a message test and focused on the throw, thinking it was unexpected... |
Run CommonJS resolver only if `error.code` is ERR_MODULE_NOT_FOUND. Avoid using absolute paths in hint by: * using a parent-relative path if the specifier is a relative path * using a `pkg/x.js` format if the specifier is bare (e.g. `pkg/x`) PR-URL: #31906 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Run CommonJS resolver only if `error.code` is ERR_MODULE_NOT_FOUND. Avoid using absolute paths in hint by: * using a parent-relative path if the specifier is a relative path * using a `pkg/x.js` format if the specifier is bare (e.g. `pkg/x`) PR-URL: #31906 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Adds hint when module specifier is a file URL. Refs: nodejs#31906
This PR tries to implement the suggestions made in issues:
When a module is not found the error message also reports the path of the module that the CommonJS resolver would have found, if any.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes