File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
packages/shared/utils/src/lib/file Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -17,10 +17,18 @@ export async function loadDefaultExport<T = unknown>(
1717) : Promise < T > {
1818 try {
1919 const fileUrl = pathToFileURL ( filePath ) . toString ( ) ;
20- // Use indirect eval to prevent webpack from replacing dynamic import with its own context
21- // This ensures the import() call works at runtime for external user files
22- const dynamicImport = new Function ( 'url' , 'return import(url)' ) ;
23- const module = await dynamicImport ( fileUrl ) ;
20+
21+ // In test environments (Vitest), use native import to avoid transformation issues
22+ // In production (webpack/bundled), use Function constructor to preserve dynamic import
23+ const isTestEnv =
24+ typeof process !== 'undefined' &&
25+ ( process . env . NODE_ENV === 'test' ||
26+ process . env . VITEST === 'true' ||
27+ typeof ( globalThis as Record < string , unknown > ) . vitest !== 'undefined' ) ;
28+
29+ const module = isTestEnv
30+ ? await import ( fileUrl )
31+ : await new Function ( 'url' , 'return import(url)' ) ( fileUrl ) ;
2432
2533 if ( ! ( 'default' in module ) ) {
2634 throw new Error (
You can’t perform that action at this time.
0 commit comments