@@ -5,7 +5,15 @@ import { isMainThread } from 'worker_threads'
55import debugModule from 'debug'
66const debug = debugModule ( 'codeceptjs:container' )
77import { MetaStep } from './step.js'
8- import { methodsOfObject , fileExists , isFunction , isAsyncFunction , installedLocally , deepMerge } from './utils.js'
8+ import {
9+ methodsOfObject ,
10+ fileExists ,
11+ isFunction ,
12+ isAsyncFunction ,
13+ installedLocally ,
14+ deepMerge ,
15+ resolveImportModulePath ,
16+ } from './utils.js'
917import { transpileTypeScript , cleanupTempFiles , fixErrorStack } from './utils/typescript.js'
1018import Translation from './translation.js'
1119import MochaFactory from './mocha/factory.js'
@@ -434,7 +442,9 @@ async function requireHelperFromModule(helperName, config, HelperClass) {
434442 try {
435443 // For built-in helpers, use direct relative import with .js extension
436444 const helperPath = `${ moduleName } .js`
437- const mod = await import ( helperPath )
445+
446+ const resolvedPath = resolveImportModulePath ( helperPath )
447+ const mod = await import ( resolvedPath )
438448 HelperClass = mod . default || mod
439449 } catch ( err ) {
440450 throw err
@@ -472,7 +482,9 @@ async function requireHelperFromModule(helperName, config, HelperClass) {
472482 // check if the new syntax export default HelperName is used and loads the Helper, otherwise loads the module that used old syntax export = HelperName.
473483 try {
474484 // Try dynamic import for both CommonJS and ESM modules
475- const mod = await import ( importPath )
485+ const resolvedPath = resolveImportModulePath ( importPath )
486+ const mod = await import ( resolvedPath )
487+
476488 if ( ! mod && ! mod . default ) {
477489 throw new Error ( `Helper module '${ moduleName } ' was not found. Make sure you have installed the package correctly.` )
478490 }
@@ -488,7 +500,7 @@ async function requireHelperFromModule(helperName, config, HelperClass) {
488500 if ( fileMapping ) {
489501 fixErrorStack ( err , fileMapping )
490502 }
491-
503+
492504 // Clean up temp files before rethrowing
493505 if ( tempJsFile ) {
494506 const filesToClean = Array . isArray ( tempJsFile ) ? tempJsFile : [ tempJsFile ]
@@ -683,7 +695,8 @@ async function loadPluginAsync(modulePath, config) {
683695 let pluginMod
684696 try {
685697 // Try dynamic import first (works for both ESM and CJS)
686- pluginMod = await import ( modulePath )
698+ const resolvedPath = resolveImportModulePath ( modulePath )
699+ pluginMod = await import ( resolvedPath )
687700 } catch ( err ) {
688701 throw new Error ( `Could not load plugin from '${ modulePath } ': ${ err . message } ` )
689702 }
@@ -890,21 +903,19 @@ async function loadSupportObject(modulePath, supportObjectName) {
890903
891904 let obj
892905 try {
893- obj = await import ( importPath )
906+ const resolvedPath = resolveImportModulePath ( importPath )
907+ obj = await import ( resolvedPath )
894908 } catch ( importError ) {
895- // Fix error stack to point to original .ts files
896909 if ( fileMapping ) {
897910 fixErrorStack ( importError , fileMapping )
898911 }
899-
900- // Clean up temp files if created before rethrowing
912+
901913 if ( tempJsFile ) {
902914 const filesToClean = Array . isArray ( tempJsFile ) ? tempJsFile : [ tempJsFile ]
903915 cleanupTempFiles ( filesToClean )
904916 }
905917 throw importError
906918 } finally {
907- // Clean up temp files if created
908919 if ( tempJsFile ) {
909920 const filesToClean = Array . isArray ( tempJsFile ) ? tempJsFile : [ tempJsFile ]
910921 cleanupTempFiles ( filesToClean )
0 commit comments