Skip to content

Commit 3f64504

Browse files
committed
improve error message for circular reexports
fixes webpack#7547
1 parent 02a955b commit 3f64504

File tree

11 files changed

+54
-2
lines changed

11 files changed

+54
-2
lines changed

lib/optimize/ConcatenatedModule.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ const getFinalName = (
108108
moduleToInfoMap,
109109
requestShortener,
110110
asCall,
111-
strictHarmonyModule
111+
strictHarmonyModule,
112+
alreadyVisited = new Set()
112113
) => {
113114
switch (info.type) {
114115
case "concatenated": {
@@ -134,6 +135,22 @@ const getFinalName = (
134135
}
135136
const reexport = info.reexportMap.get(exportName);
136137
if (reexport) {
138+
if (alreadyVisited.has(reexport)) {
139+
throw new Error(
140+
`Circular reexports ${Array.from(
141+
alreadyVisited,
142+
e =>
143+
`"${e.module.readableIdentifier(requestShortener)}".${
144+
e.exportName
145+
}`
146+
).join(
147+
" --> "
148+
)} -(circular)-> "${reexport.module.readableIdentifier(
149+
requestShortener
150+
)}".${reexport.exportName}`
151+
);
152+
}
153+
alreadyVisited.add(reexport);
137154
const refInfo = moduleToInfoMap.get(reexport.module);
138155
if (refInfo) {
139156
// module is in the concatenation
@@ -143,7 +160,8 @@ const getFinalName = (
143160
moduleToInfoMap,
144161
requestShortener,
145162
asCall,
146-
strictHarmonyModule
163+
strictHarmonyModule,
164+
alreadyVisited
147165
);
148166
}
149167
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { something } from "./a";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { something } from "./a";
2+
3+
something();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
import { something, other } from "./b";
3+
4+
export {
5+
something as other,
6+
other as something
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {something} from "./b";
2+
3+
something();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { something } from "./c2";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { something } from "./c1";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {something} from "./c1";
2+
3+
something();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = [
2+
[/Circular reexports "\.\/a.js"\.something -\(circular\)-> "\.\/a.js"\.something/],
3+
[/Circular reexports "\.\/b.js"\.other --> "\.\/b.js"\.something -\(circular\)-> "\.\/b.js"\.other/],
4+
[/Circular reexports "\.\/c2.js"\.something --> "\.\/c1.js"\.something -\(circular\)-> "\.\/c2.js"\.something/]
5+
];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
it("should not crash on incorrect exports", function() {
2+
if(Math.random() < -1) {
3+
import(/* webpackChunkName: "a" */ "./aa");
4+
import(/* webpackChunkName: "b" */ "./bb");
5+
import(/* webpackChunkName: "c" */ "./cc");
6+
}
7+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
mode: "production"
3+
};

0 commit comments

Comments
 (0)