ts-jest: [Bug]: ts-jest 29.2 breaks dependency transform
Version
29.2.3
Steps to reproduce
- clone https://github.com/repobuddy/repobuddy/tree/ts-jest-29.2-issue
- pnpm i
- pnpm build
- 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
- fix: revert support implementation for `Node16/NodeNext` - For CJS mode, `module` is always `CommonJS` - For ESM mode, `module` with value `Node16/NodeNext` will use `ESNext`, otherwise use the value... — committed to kulshekhar/ts-jest by ahnpnl 2 years ago
- fix: revert support implementation for `Node16/NodeNext` - For CJS mode, `module` is always `CommonJS` - For ESM mode, `module` with value `Node16/NodeNext` will use `ESNext`, otherwise use the value... — committed to kulshekhar/ts-jest by ahnpnl 2 years ago
- fix: revert support implementation for `Node16/NodeNext` - For CJS mode, `module` is always `CommonJS` - For ESM mode, `module` with value `Node16/NodeNext` will use `ESNext`, otherwise use the value... — committed to SimenB/ts-jest by ahnpnl 2 years ago
I’m thinking about reverting the support for
Node16/NodeNextand 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
Node16andtype: "module"inpackage.jsonwhich makes typescript API to transpile codes into ESM syntax. To fix it, you should setmodule: "CommonJS"for your test