You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: improve PackagePathNotExported error message with condition names
Improves the error message to match enhanced-resolve behavior from
commit f1bc1c2, providing better developer experience when debugging
export resolution failures.
Changes:
- Updated `ResolveError::PackagePathNotExported` to include condition names
- Added `ConditionNames` type with custom Display formatting
- Error message now shows which conditions were checked
Before:
Package subpath './foo' is not defined by "exports" in /path/to/package.json
After:
"./foo" is not exported under the conditions ["node", "import"] from package /path/to (see exports field in /path/to/package.json)
Fixes: Cross-reference with enhanced-resolve#460
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: src/error.rs
+32-2Lines changed: 32 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -88,8 +88,13 @@ pub enum ResolveError {
88
88
#[error(r#"Invalid "exports" target "{0}" defined for '{1}' in the package config {2}"#)]
89
89
InvalidPackageTarget(String,String,PathBuf),
90
90
91
-
#[error(r#"Package subpath '{0}' is not defined by "exports" in {1}"#)]
92
-
PackagePathNotExported(String,PathBuf),
91
+
#[error(r#""{subpath}" is not exported under {conditions} from package {package_path} (see exports field in {package_json_path})"#)]
92
+
PackagePathNotExported{
93
+
subpath:String,
94
+
package_path:PathBuf,
95
+
package_json_path:PathBuf,
96
+
conditions:ConditionNames,
97
+
},
93
98
94
99
#[error(r#"Invalid package config "{0}", "exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only."#)]
95
100
InvalidPackageConfig(PathBuf),
@@ -201,6 +206,31 @@ impl From<Vec<PathBuf>> for CircularPathBufs {
201
206
}
202
207
}
203
208
209
+
/// Helper type for formatting condition names in error messages
Copy file name to clipboardExpand all lines: src/tests/exports_field.rs
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -71,13 +71,13 @@ fn test_simple() {
71
71
("relative path should not work with exports field", f.clone(),"./node_modules/exports-field/dist/main.js",ResolveError::NotFound("./node_modules/exports-field/dist/main.js".into())),
72
72
("backtracking should not work for request", f.clone(),"exports-field/dist/../../../a.js",ResolveError::InvalidPackageTarget("./lib/../../../a.js".to_string(),"./dist/".to_string(), p.clone())),
73
73
("backtracking should not work for exports field target", f.clone(),"exports-field/dist/a.js",ResolveError::InvalidPackageTarget("./../../a.js".to_string(),"./dist/a.js".to_string(), p.clone())),
("request ending with slash #1", f.clone(),"exports-field/",ResolveError::PackagePathNotExported{subpath:"./".to_string(),package_path: f.join("node_modules/exports-field"),package_json_path:p.clone(),conditions:vec!["webpack".into()].into()}),
76
+
("request ending with slash #2", f.clone(),"exports-field/dist/",ResolveError::PackagePathNotExported{subpath:"./dist/".to_string(),package_path: f.join("node_modules/exports-field"),package_json_path:p.clone(),conditions:vec!["webpack".into()].into()}),
77
+
("request ending with slash #3", f.clone(),"exports-field/lib/",ResolveError::PackagePathNotExported{subpath:"./lib/".to_string(),package_path: f.join("node_modules/exports-field"),package_json_path: p,conditions:vec!["webpack".into()].into()}),
78
78
("should throw error if target is invalid", f4,"exports-field",ResolveError::InvalidPackageTarget("./a/../b/../../pack1/index.js".to_string(),".".to_string(), p4)),
79
79
("throw error if exports field is invalid", f.clone(),"invalid-exports-field",ResolveError::InvalidPackageConfig(f.join("node_modules/invalid-exports-field/package.json"))),
80
-
("should throw error if target is 'null'", f5,"m/features/internal/file.js",ResolveError::PackagePathNotExported("./features/internal/file.js".to_string(),p5)),
80
+
("should throw error if target is 'null'", f5.clone(),"m/features/internal/file.js",ResolveError::PackagePathNotExported{subpath:"./features/internal/file.js".to_string(),package_path: f5.join("node_modules/m"),package_json_path: p5,conditions:vec!["webpack".into()].into()}),
0 commit comments