serverless/lib/utils/require-with-import-fallback.js
2024-05-29 11:51:04 -04:00

15 lines
383 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
}
}