diff --git a/internal/bundler_tests/bundler_packagejson_test.go b/internal/bundler_tests/bundler_packagejson_test.go index 19aa3ee99c..8f89eadf2a 100644 --- a/internal/bundler_tests/bundler_packagejson_test.go +++ b/internal/bundler_tests/bundler_packagejson_test.go @@ -3002,3 +3002,36 @@ node_modules/foo/package.json: NOTE: The "default" condition comes earlier and w `, }) } + +// See: https://github.com/evanw/esbuild/issues/3887 +func TestPackageJsonExportsDefaultWarningIssue3887(t *testing.T) { + packagejson_suite.expectBundled(t, bundled{ + files: map[string]string{ + "/entry.js": ` + import "foo" + `, + "/node_modules/foo/dist/index.js": ` + success() + `, + "/node_modules/foo/package.json": ` + { + "exports": { + ".": { + "node": "./dist/index.js", + "require": "./dist/index.js", + "import": "./dist/index.esm.js", + "default": "./dist/index.esm.js" + } + } + } + `, + }, + entryPaths: []string{"/entry.js"}, + options: config.Options{ + Mode: config.ModeBundle, + Platform: config.PlatformNode, + AbsOutputFile: "/out.js", + }, + debugLogs: true, + }) +} diff --git a/internal/bundler_tests/snapshots/snapshots_packagejson.txt b/internal/bundler_tests/snapshots/snapshots_packagejson.txt index 16a55913d1..8a1bd8f523 100644 --- a/internal/bundler_tests/snapshots/snapshots_packagejson.txt +++ b/internal/bundler_tests/snapshots/snapshots_packagejson.txt @@ -585,6 +585,12 @@ TestPackageJsonExportsDefaultOverImportAndRequire // Users/user/project/node_modules/pkg/default.js console.log("SUCCESS"); +================================================================================ +TestPackageJsonExportsDefaultWarningIssue3887 +---------- /out.js ---------- +// node_modules/foo/dist/index.js +success(); + ================================================================================ TestPackageJsonExportsEntryPointImportOverRequire ---------- /out.js ---------- diff --git a/internal/resolver/package_json.go b/internal/resolver/package_json.go index acf5a220f6..068acdea0e 100644 --- a/internal/resolver/package_json.go +++ b/internal/resolver/package_json.go @@ -710,7 +710,8 @@ func parseImportsExportsMap(source logger.Source, log logger.Log, json js_ast.Ex // Track "dead" conditional branches that can never be reached if foundDefault.Len != 0 || (foundImport.Len != 0 && foundRequire.Len != 0) { deadCondition.ranges = append(deadCondition.ranges, keyRange) - if deadCondition.reason == "" { + // Note: Don't warn about the "default" condition as it's supposed to be a catch-all condition + if deadCondition.reason == "" && key != "default" { if foundDefault.Len != 0 { deadCondition.reason = "\"default\"" deadCondition.notes = []logger.MsgData{