Skip to content

BUG: correctly handle typescript module imports in ESM environments (this is a known interop issue) #5603

Description

@kobenguyent

Hi! 👋

Today I used patch-package to patch codeceptjs@4.0.3 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/codeceptjs/lib/container.js b/node_modules/codeceptjs/lib/container.js
index 3a00d42..13be7b0 100644
--- a/node_modules/codeceptjs/lib/container.js
+++ b/node_modules/codeceptjs/lib/container.js
@@ -449,7 +449,7 @@ async function requireHelperFromModule(helperName, config, HelperClass) {
     if (ext === '.ts') {
       try {
         // Use the TypeScript transpilation utility
-        const typescript = await import('typescript')
+        const typescript = ((await import('typescript')).default || (await import('typescript')))
         const { tempFile, allTempFiles, fileMapping: mapping } = await transpileTypeScript(importPath, typescript)
 
         debug(`Transpiled TypeScript helper: ${importPath} -> ${tempFile}`)
@@ -862,7 +862,7 @@ async function loadSupportObject(modulePath, supportObjectName) {
       if (ext === '.ts') {
         try {
           // Use the TypeScript transpilation utility
-          const typescript = await import('typescript')
+          const typescript = ((await import('typescript')).default || (await import('typescript')))
           const { tempFile, allTempFiles, fileMapping: mapping } = await transpileTypeScript(importPath, typescript)
 
           debug(`Transpiled TypeScript file: ${importPath} -> ${tempFile}`)

This issue body was partially generated by patch-package.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions