Skip to content

Commit f1bc1c2

Browse files
authored
fix: note the conditions under which the request couldn't be found (#460)
1 parent 52b61d0 commit f1bc1c2

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lib/ExportsFieldPlugin.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,14 @@ module.exports = class ExportsFieldPlugin {
114114
}
115115

116116
if (paths.length === 0) {
117+
const conditions = [...this.conditionNames];
118+
const conditionsStr =
119+
conditions.length === 1
120+
? `the condition "${conditions[0]}"`
121+
: `the conditions ${JSON.stringify(conditions)}`;
117122
return callback(
118123
new Error(
119-
`Package path ${remainingRequest} is not exported from package ${request.descriptionFileRoot} (see exports field in ${request.descriptionFilePath})`,
124+
`"${remainingRequest}" is not exported under ${conditionsStr} from package ${request.descriptionFileRoot} (see exports field in ${request.descriptionFilePath})`,
120125
),
121126
);
122127
}

test/exportsField.test.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,7 +2352,7 @@ describe("exportsFieldPlugin", () => {
23522352
resolver.resolve({}, fixture2, "exports-field?foo", {}, (err, result) => {
23532353
if (!err) return done(new Error(`expect error, got ${result}`));
23542354
expect(err).toBeInstanceOf(Error);
2355-
expect(err.message).toMatch(/Package path \.\/\?foo is not exported/);
2355+
expect(err.message).toMatch(/"\.\/\?foo" is not exported/);
23562356
done();
23572357
});
23582358
});
@@ -2381,7 +2381,7 @@ describe("exportsFieldPlugin", () => {
23812381
resolver.resolve({}, fixture2, "exports-field#foo", {}, (err, result) => {
23822382
if (!err) return done(new Error(`expect error, got ${result}`));
23832383
expect(err).toBeInstanceOf(Error);
2384-
expect(err.message).toMatch(/Package path \.\/#foo is not exported/);
2384+
expect(err.message).toMatch(/"\.\/#foo" is not exported/);
23852385
done();
23862386
});
23872387
});
@@ -2470,7 +2470,9 @@ describe("exportsFieldPlugin", () => {
24702470
(err, result) => {
24712471
if (!err) return done(new Error(`expect error, got ${result}`));
24722472
expect(err).toBeInstanceOf(Error);
2473-
expect(err.message).toMatch(/not exported from package/);
2473+
expect(err.message).toMatch(
2474+
/not exported under the condition "webpack" from package/,
2475+
);
24742476
done();
24752477
},
24762478
);
@@ -2837,7 +2839,7 @@ describe("exportsFieldPlugin", () => {
28372839
if (!err) return done(new Error(`expect error, got ${result}`));
28382840
expect(err).toBeInstanceOf(Error);
28392841
expect(err.message).toMatch(
2840-
/Package path \.\/features\/internal\/file\.js is not exported/,
2842+
/"\.\/features\/internal\/file\.js" is not exported/,
28412843
);
28422844
done();
28432845
},
@@ -2937,9 +2939,7 @@ describe("exportsFieldPlugin", () => {
29372939
resolver.resolve({}, fixture, "pkg/string.js", {}, (err, result) => {
29382940
if (!err) return done(new Error(`expect error, got ${result}`));
29392941
expect(err).toBeInstanceOf(Error);
2940-
expect(err.message).toMatch(
2941-
/Package path \.\/string\.ts is not exported/,
2942-
);
2942+
expect(err.message).toMatch(/"\.\/string\.ts" is not exported/);
29432943
done();
29442944
});
29452945
});
@@ -2962,9 +2962,7 @@ describe("exportsFieldPlugin", () => {
29622962
resolver.resolve({}, fixture, "pkg/string.js", {}, (err, result) => {
29632963
if (!err) return done(new Error(`expect error, got ${result}`));
29642964
expect(err).toBeInstanceOf(Error);
2965-
expect(err.message).toMatch(
2966-
/Package path \.\/string\.ts is not exported/,
2967-
);
2965+
expect(err.message).toMatch(/"\.\/string\.ts" is not exported/);
29682966
done();
29692967
});
29702968
});

0 commit comments

Comments
 (0)