Files
klz-cables.com/.pnpm-store/v10/files/8e/af4d0f7592db863948455c71d4f18af12968a7755ba4c62035a3f7666779b704bc0a118524b6e74b962cebbf22b78d958471bb6ac53bfab466383f5a6e1c7d
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

24 lines
1.3 KiB
Plaintext

import path from 'path';
import { pathToFileURL } from 'url';
/**
* Dynamically imports a module from a file path or module specifier.
*
* Uses a direct `import()` in Vitest (where eval'd imports fail with ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING),
* and `eval(`import(...)`)` elsewhere to hide the import from Next.js bundler static analysis.
*
* @param modulePathOrSpecifier - Either an absolute file path or a module specifier (package name)
*/ export async function dynamicImport(modulePathOrSpecifier) {
// Convert absolute file paths to file:// URLs, but leave package specifiers as-is
const importPath = path.isAbsolute(modulePathOrSpecifier) ? pathToFileURL(modulePathOrSpecifier).href : modulePathOrSpecifier;
// Vitest runs tests in a VM context where eval'd dynamic imports fail with
// ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING. Use direct import in test environment.
if (process.env.VITEST) {
return await import(/* webpackIgnore: true */ importPath);
}
// Without the eval, the Next.js bundler will throw this error when encountering the import statement:
// ⚠ Compiled with warnings in X.Xs
// Critical dependency: the request of a dependency is an expression
return await eval(`import('${importPath}')`);
}
//# sourceMappingURL=dynamicImport.js.map