Skip to content
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

Error messages are not precise enough #223

Closed
ehmicky opened this issue May 20, 2020 · 4 comments · Fixed by #234
Closed

Error messages are not precise enough #223

ehmicky opened this issue May 20, 2020 · 4 comments · Fixed by #234

Comments

@ehmicky
Copy link

ehmicky commented May 20, 2020

I tried to run resolve against a library which had an invalid main field in package.json.

With require.resolve(), the error message is:

> require.resolve('mylib')
Uncaught:
Error: Cannot find module '/home/me/code/cv-website/node_modules/mylib/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:322:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:683:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1007:27)
    at Function.resolve (internal/modules/cjs/helpers.js:78:19) {
  code: 'MODULE_NOT_FOUND',
  path: '/home/me/code/cv-website/node_modules/mylib/package.json',
  requestPath: 'mylib'
}

With resolve, it is:

> resolve.sync('mylib')
Uncaught Error: Cannot find module 'mylib' from '.'
    at Function.resolveSync [as sync] (/home/me/code/cv-website/node_modules/resolve/lib/sync.js:89:15) {
  code: 'MODULE_NOT_FOUND'
}

Missing error information was critical in my use case, and it took some time to figure out why resolve was failing.

@ljharb
Copy link
Member

ljharb commented May 20, 2020

I’d be quite happy to review a PR that improved error messages.

@ehmicky
Copy link
Author

ehmicky commented May 20, 2020

I am not sure I would have time for this unfortunately.

@matthew-dean
Copy link

Related to this, does the error list all variants tried, if you have multiple paths and extensions?

@Cheesetouched
Copy link
Contributor

Sounds interesting. Happy to look into this. Would drop updates here as I go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants