diff --git a/package.json b/package.json index 3a3969f..e498e24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@artus/core", - "version": "2.2.0", + "version": "2.2.1", "description": "Core package of Artus", "main": "./lib/index.js", "types": "./lib/index.d.ts", @@ -72,4 +72,4 @@ "ci": { "version": "16, 18" } -} +} \ No newline at end of file diff --git a/src/utils/compatible_require.ts b/src/utils/compatible_require.ts index c33337b..eb09946 100644 --- a/src/utils/compatible_require.ts +++ b/src/utils/compatible_require.ts @@ -15,10 +15,14 @@ export default async function compatibleRequire(path: string, origin = false): P /* eslint-disable-next-line @typescript-eslint/no-var-requires */ requiredModule = tslib.__importStar(require(path)); assert(requiredModule, `module '${path}' exports is undefined`); - } catch { - requiredModule = await import(path); - assert(requiredModule, `module '${path}' exports is undefined`); - requiredModule = requiredModule.__esModule ? requiredModule.default ?? requiredModule : requiredModule; + } catch (err) { + if (err.code === 'ERR_REQUIRE_ESM') { + requiredModule = await import(path); + assert(requiredModule, `module '${path}' exports is undefined`); + requiredModule = requiredModule.__esModule ? requiredModule.default ?? requiredModule : requiredModule; + } else { + throw err; + } } return origin ? requiredModule : (requiredModule.default || requiredModule);