serverless/lib/utils/require-with-import-fallback.js
2024-04-17 21:38:24 -07:00

15 lines
388 B
JavaScript

// Import the dynamic import helper
import importESM from './import-esm.js';
export default async (modPath) => {
try {
return await import(modPath);
} catch (error) {
// Fallback to import() if the runtime supports native ESM and throws specific error
if (error.code === 'ERR_REQUIRE_ESM') {
return (await importESM(modPath)).default;
}
throw error;
}
};