Skip to content

fix(lib/node): change ERR_INVALID_PACKAGE_TARGET to ERR_PACKAGE_PATH_NOT_EXPORTED when no package.json#exports condition matches #29841

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sgasho
Copy link
Contributor

@sgasho sgasho commented Jun 22, 2025

related: #29374

The error message changed from ERR_INVALID_PACKAGE_TARGET to ERR_PACKAGE_PATH_NOT_EXPORTED when no package.json#exports condition matched.
Node.js uses the same error message in this situation.

There might be a more appropriate error message, but for now, I've matched the default behavior of Node.js.

Supplements

Why just removing InvalidPackageTargetError at resolve_package_target_inner leads to PackagePathNotExportedError is that Ok(None) from resolve_package_target_inner will be passed to resolve_package_target -> package_exports_resolve_internal then package_exports_resolve_internal considers None as a PackagePathNotExportError

package_exports_resolve_internal

        let resolved = self.resolve_package_target(
          package_json_path,
          target,
          "",
          package_subpath,
          maybe_referrer,
          resolution_mode,
          false,
          false,
          conditions,
          resolution_kind,
        )?;
        return match resolved {
          Some(resolved) => Ok(resolved),
          None => Err(
            PackagePathNotExportedError {
              pkg_json_path: package_json_path.to_path_buf(),
              subpath: package_subpath.to_string(),
              maybe_referrer: maybe_referrer.map(|r| r.display()),
              resolution_kind,
            }
            .into(),
          ),
        };

Screenshots

Before

スクリーンショット 2025-06-22 12 43 10

After

スクリーンショット 2025-06-22 12 42 28

reference: node.js

スクリーンショット 2025-06-22 16 15 15

@sgasho sgasho marked this pull request as ready for review June 22, 2025 07:48
@dsherret dsherret self-requested a review June 23, 2025 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant