Improve the error message for missing modules
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
Currently, the error that is produced in case of a missing module is not really user friendly:
node:internal/process/esm_loader:74
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'not-existing-module' imported from /Users/matteo/temp/a.mjs
at new NodeError (node:internal/errors:363:5)
at packageResolve (node:internal/modules/esm/resolve:698:9)
at moduleResolve (node:internal/modules/esm/resolve:739:18)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:853:11)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:73:40)
at link (node:internal/modules/esm/module_job:72:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
Rust for example provide more user friendly errors:
error[E0432]: unresolved import `crate::constants`
--> src/primes.rs:5:12
|
5 | use crate::constants::{FNUM, PNUM, SMAX};
| ^^^^^^^^^ maybe a missing crate `constants`?
Note that our errors do not list which line the dependency was not specified.
What do you think? I think it would improve things long term.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the missing-module path through internal/process/esm_loader and internal/modules/esm/resolve and loader, using the shown ERR_MODULE_NOT_FOUND output as the baseline. The issue does not name a test or prescribe exact wording; done would mean agreeing on and implementing a clearer error that identifies where the dependency was requested, with coverage for the resulting message.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100