File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
packages/vite/src/module-runner Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,16 @@ function customizationHookResolve(
3333 return nextResolve ( specifier , context )
3434}
3535
36+ // Ensure that we only register the hook once
37+ // Otherwise, a hook will be registered for each createImportMetaResolver call
38+ // and eventually cause "Maximum call stack size exceeded" errors
39+ let isHookRegistered = false
40+
3641export function createImportMetaResolver ( ) : ImportMetaResolver | undefined {
42+ if ( isHookRegistered ) {
43+ return importMetaResolveWithCustomHook
44+ }
45+
3746 let module : typeof import ( 'node:module' ) | undefined
3847 try {
3948 module =
@@ -53,6 +62,7 @@ export function createImportMetaResolver(): ImportMetaResolver | undefined {
5362 if ( module . registerHooks ) {
5463 // eslint-disable-next-line n/no-unsupported-features/node-builtins -- we checked the existence
5564 module . registerHooks ( { resolve : customizationHookResolve } )
65+ isHookRegistered = true
5666 return importMetaResolveWithCustomHook
5767 }
5868
@@ -73,6 +83,7 @@ export function createImportMetaResolver(): ImportMetaResolver | undefined {
7383 throw e
7484 }
7585
86+ isHookRegistered = true
7687 return importMetaResolveWithCustomHook
7788}
7889
You can’t perform that action at this time.
0 commit comments