Skip to content

Commit 7cecbcc

Browse files
authored
fix(module): protect clearRequireCache against infinite recursion (#7966)
1 parent 447340e commit 7cecbcc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/utils/src/cjs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ export function clearRequireCache (id) {
2020
entry.parent.children = entry.parent.children.filter(e => e.id !== id)
2121
}
2222

23+
// Needs to be cleared before children, to protect against circular deps (#7966)
24+
delete require.cache[id]
25+
2326
for (const child of entry.children) {
2427
clearRequireCache(child.id)
2528
}
26-
27-
delete require.cache[id]
2829
}
2930

3031
export function scanRequireTree (id, files = new Set()) {

0 commit comments

Comments
 (0)