Skip to content

[Bug]: Linux/WSL: ts-jest Fails with ReferenceError: exports is not defined in setupFiles on First Run (Clean Cache), Fixes Itself After Cache Update #4774

@yegorpetrov

Description

@yegorpetrov

Version

29.3.1

Steps to reproduce

Minimal repro (incl readme with more details): https://github.com/yegorpetrov/ts-jest-issue-repro/tree/no-eslint

  1. Use macOS, ubuntu-latest of GitHub or WSL/Ubuntu. May be some other Linux env (did not check) but not Windows.
  2. npm i.
  3. Check node node_modules/jest/bin/jest.js --showConfig to see where the cacheDirectory is (e.g. /tmp/jest_rs).
  4. Empty the cache directory.
  5. Observe the error: npm run test yields ReferenceError: exports is not defined in "jest.setup-files.ts".
  6. Try npm run test again to see that the error does not go away.
  7. Navigate to jest.setup-files.ts and make any edit, e.g. insert a meaningless space character.
  8. npm run test again - there is no error anymore
  9. Clean the cache directory and do npm run test once more - the error will reappear.

Expected behavior

I expect ts-jest to execute the test without failures and additional manipulations with the cache or the setup file.

Actual behavior

ts-jest reports an ESM error ReferenceError: exports is not defined in a setup file, but only on Linux (WSL or ubuntu-latest in Github runners).

Debug log

ts-jest-win.log
ts-jest-wsl.log

Additional context

No response

Environment

System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa) **WSL**
    CPU: (12) x64 AMD Ryzen 5 4600H with Radeon Graphics
  Binaries:
    Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
    Yarn: 1.22.10 - /usr/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0

macOS seems to be affected too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions