From 9e977cd6aaabc6618421578654becafa1ab611f5 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 15 Dec 2022 21:15:25 -0500 Subject: fix(npm): improve exports resolution when type checking (#17071) Closes #17012 --- ext/node/errors.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'ext/node/errors.rs') diff --git a/ext/node/errors.rs b/ext/node/errors.rs index 929f51e1b..b489cb937 100644 --- a/ext/node/errors.rs +++ b/ext/node/errors.rs @@ -1,5 +1,7 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +use std::path::PathBuf; + use deno_core::error::generic_error; use deno_core::error::type_error; use deno_core::error::AnyError; @@ -61,13 +63,26 @@ pub fn err_invalid_package_target( ) -> AnyError { let rel_error = !is_import && !target.is_empty() && !target.starts_with("./"); let mut msg = "[ERR_INVALID_PACKAGE_TARGET]".to_string(); + let pkg_json_path = PathBuf::from(pkg_path).join("package.json"); if key == "." { assert!(!is_import); - msg = format!("{} Invalid \"exports\" main target {} defined in the package config {}package.json", msg, target, pkg_path) + msg = format!( + "{} Invalid \"exports\" main target {} defined in the package config {}", + msg, + target, + pkg_json_path.display() + ) } else { let ie = if is_import { "imports" } else { "exports" }; - msg = format!("{} Invalid \"{}\" target {} defined for '{}' in the package config {}package.json", msg, ie, target, key, pkg_path) + msg = format!( + "{} Invalid \"{}\" target {} defined for '{}' in the package config {}", + msg, + ie, + target, + key, + pkg_json_path.display() + ) }; if let Some(base) = maybe_referrer { -- cgit v1.2.3