serverless/lib/utils/require-with-import-fallback.js
2022-12-08 12:58:29 +01:00

14 lines
310 B
JavaScript

'use strict';
module.exports = async (modPath) => {
try {
return require(modPath);
} catch (error) {
// Fallback to import() if the runtime supports native ESM
if (error.code === 'ERR_REQUIRE_ESM') {
return (await require('./import-esm')(modPath)).default;
}
throw error;
}
};