diff --git a/lib/ExportsFieldPlugin.js b/lib/ExportsFieldPlugin.js index b6730f0..cba3cc7 100644 --- a/lib/ExportsFieldPlugin.js +++ b/lib/ExportsFieldPlugin.js @@ -114,9 +114,14 @@ module.exports = class ExportsFieldPlugin { } if (paths.length === 0) { + const conditions = [...this.conditionNames]; + const conditionsStr = + conditions.length === 1 + ? `the condition "${conditions[0]}"` + : `the conditions ${JSON.stringify(conditions)}`; return callback( new Error( - `Package path ${remainingRequest} is not exported from package ${request.descriptionFileRoot} (see exports field in ${request.descriptionFilePath})`, + `"${remainingRequest}" is not exported under ${conditionsStr} from package ${request.descriptionFileRoot} (see exports field in ${request.descriptionFilePath})`, ), ); } diff --git a/test/exportsField.test.js b/test/exportsField.test.js index e93b1e5..337eb07 100644 --- a/test/exportsField.test.js +++ b/test/exportsField.test.js @@ -2352,7 +2352,7 @@ describe("exportsFieldPlugin", () => { resolver.resolve({}, fixture2, "exports-field?foo", {}, (err, result) => { if (!err) return done(new Error(`expect error, got ${result}`)); expect(err).toBeInstanceOf(Error); - expect(err.message).toMatch(/Package path \.\/\?foo is not exported/); + expect(err.message).toMatch(/"\.\/\?foo" is not exported/); done(); }); }); @@ -2381,7 +2381,7 @@ describe("exportsFieldPlugin", () => { resolver.resolve({}, fixture2, "exports-field#foo", {}, (err, result) => { if (!err) return done(new Error(`expect error, got ${result}`)); expect(err).toBeInstanceOf(Error); - expect(err.message).toMatch(/Package path \.\/#foo is not exported/); + expect(err.message).toMatch(/"\.\/#foo" is not exported/); done(); }); }); @@ -2470,7 +2470,9 @@ describe("exportsFieldPlugin", () => { (err, result) => { if (!err) return done(new Error(`expect error, got ${result}`)); expect(err).toBeInstanceOf(Error); - expect(err.message).toMatch(/not exported from package/); + expect(err.message).toMatch( + /not exported under the condition "webpack" from package/, + ); done(); }, ); @@ -2837,7 +2839,7 @@ describe("exportsFieldPlugin", () => { if (!err) return done(new Error(`expect error, got ${result}`)); expect(err).toBeInstanceOf(Error); expect(err.message).toMatch( - /Package path \.\/features\/internal\/file\.js is not exported/, + /"\.\/features\/internal\/file\.js" is not exported/, ); done(); }, @@ -2937,9 +2939,7 @@ describe("exportsFieldPlugin", () => { resolver.resolve({}, fixture, "pkg/string.js", {}, (err, result) => { if (!err) return done(new Error(`expect error, got ${result}`)); expect(err).toBeInstanceOf(Error); - expect(err.message).toMatch( - /Package path \.\/string\.ts is not exported/, - ); + expect(err.message).toMatch(/"\.\/string\.ts" is not exported/); done(); }); }); @@ -2962,9 +2962,7 @@ describe("exportsFieldPlugin", () => { resolver.resolve({}, fixture, "pkg/string.js", {}, (err, result) => { if (!err) return done(new Error(`expect error, got ${result}`)); expect(err).toBeInstanceOf(Error); - expect(err.message).toMatch( - /Package path \.\/string\.ts is not exported/, - ); + expect(err.message).toMatch(/"\.\/string\.ts" is not exported/); done(); }); });