ts-jest: [Bug]: ts-jest 29.2 breaks dependency transform

Version

29.2.3

Steps to reproduce

  1. clone https://github.com/repobuddy/repobuddy/tree/ts-jest-29.2-issue
  2. pnpm i
  3. pnpm build
  4. pnpm jest test

Expected behavior

test pass

Actual behavior

    /home/runner/work/repobuddy/repobuddy/packages/jest/ts/tests/chalk.spec.ts:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { it } from '@jest/globals';
                                                                                      ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at Runtime.createScriptFromCode (../../node_modules/.pnpm/jest-runtime@29.7.0/node_modules/jest-runtime/build/index.js:1505:14)

Debug log

see above

Additional context

It is working with ts-jest 29.1

the transform config is:

  transform: {
    '^.+\\.(ts|tsx|cts|mts)$': ['ts-jest', [{
      isolatedModules: true,
      useESM: true,
    }]],
    '\\.m?jsx?$': 'jest-esm-transformer-2'
  },
  transformIgnorePatterns: [],

I have also tried to use transformIgnorePatterns but also not working.

Environment

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
    pnpm: 9.5.0 - ~/.nvm/versions/node/v20.12.2/bin/pnpm
    bun: 0.1.6 - ~/.bun/bin/bun
  npmPackages:
    jest: ^29.7.0 => 29.7.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 18

Commits related to this issue

Most upvoted comments

I’m thinking about reverting the support for Node16/NodeNext and leave it for the next major release. That would solve quite some issues.

Hi, your issue is the same as #4464, you can check my explanation here https://github.com/kulshekhar/ts-jest/issues/4464#issuecomment-2244381931

The main reason is that your test is using Node16 and type: "module" in package.json which makes typescript API to transpile codes into ESM syntax. To fix it, you should set module: "CommonJS" for your test