Skip to content

modules: missing exports as MODULE_NOT_FOUND

It seems I missed this change when reviewing https://github.com/nodejs/node/pull/28759, where previously the package.json "exports" would throw a MODULE_NOT_FOUND error if trying to import something from a package that was a missing export (changed on this line here - https://github.com/nodejs/node/pull/28759/files#diff-4a5950be44f56dfca2e7fa3c4e1fc0e4).

I think it is quite important for the core resolver to have a unified MODULE_NOT_FOUND error instead of splitting this off into different cases, as any tool that uses a resolver typically wants to be able to filter these errors specifically, and having many variations of not found error codes will not help that.

Just like the package.json "main" not being found is still a MODULE_NOT_FOUND error and not a MAIN_NOT_FOUND, I think we should ensure missing "exports" are still a MODULE_NOT_FOUND error.

This implements that approach for both the CJS and ESM resolvers.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading