Skip to content

Commit a435a5e

Browse files
author
DavertMik
committed
fixed loading codeceptjs
1 parent cef1ebc commit a435a5e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/container.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,23 @@ async function requireHelperFromModule(helperName, config, HelperClass) {
377377
try {
378378
// Try dynamic import for both CommonJS and ESM modules
379379
const mod = await import(moduleName)
380+
if (!mod && !mod.default) {
381+
throw new Error(`Helper module '${moduleName}' was not found. Make sure you have installed the package correctly.`)
382+
}
380383
HelperClass = mod.default || mod
381384
} catch (err) {
382-
if (err.code === 'ERR_MODULE_NOT_FOUND') {
385+
if (err.code === 'ERR_REQUIRE_ESM' || (err.message && err.message.includes('ES module'))) {
386+
// This is an ESM module, use dynamic import
387+
try {
388+
const pathModule = await import('path')
389+
const absolutePath = pathModule.default.resolve(moduleName)
390+
const mod = await import(absolutePath)
391+
HelperClass = mod.default || mod
392+
debug(`helper ${helperName} loaded via ESM import`)
393+
} catch (importErr) {
394+
throw new Error(`Helper module '${moduleName}' could not be imported as ESM: ${importErr.message}`)
395+
}
396+
} else if (err.code === 'MODULE_NOT_FOUND') {
383397
throw new Error(`Helper module '${moduleName}' was not found. Make sure you have installed the package correctly.`)
384398
} else {
385399
throw err

0 commit comments

Comments
 (0)