ts-jest: TypeError: Jest: a transform must export something.

🐛 Bug Report

After upgrading from jest 23.6.3 to 27.0.1 and running our test suite we get the following error message:

TypeError: Jest: a transform must export something.

image

To Reproduce

  1. Clone the GIT repo
  2. Upgrade jest:
   name  range   from       to      url
>( ) jest  latest  26.6.3  ❯  27.0.1  https://jestjs.io/
  1. Run yarn test

Expected behavior

No error message

Debug log:

# content of ts-jest.log :
{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"26.5.6"},"message":"creating jest presets not handling JavaScript files","sequence":1,"time":"2021-05-25T13:21:43.451Z"}
{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"26.5.6"},"message":"creating jest presets not handling JavaScript files","sequence":2,"time":"2021-05-25T13:21:43.474Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"26.5.6"},"message":"creating Importer singleton","sequence":3,"time":"2021-05-25T13:21:45.906Z"}

envinfo

System:
    OS: Windows Server 2016
    Node version: 14.15.4

Npm packages:
    jest: 27.0.1
    ts-jest: 26.5.6
    typescript: 4.2.4

Related issue

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 50
  • Comments: 29

Commits related to this issue

Most upvoted comments

pls clear Jest cache and use ts-jest 27.0.0

I used this: npx jest --clearCache which showed this message after running: Cleared /private/var/folders/mr/pkt42jm120gbnm9lddwm_n9cl2tb8h/T/jest_alc100 That seemed to have cleared the cache

adding to the previous comment – clearing the cache didn’t solve the issue for me. I’m still getting the original error mentioned in this thread.

You should clear Jest cache via jest —clearCache

Not sure if it will help, but I had this issue because my version of jest globally differed from the version in the project I was working on. Running sudo npm i -g jest@latest resolved the issue for me.

Met the same issue with "jest": "^27.0.1" and fixed by revert to "jest": "^26.4.2",.

You have to use ts-jest 27.0.1 and clear jest cache @Jeff-Tian

Thank you for the feedback. It might be a good idea to keep one of the issues open so it’s easy to find. That’s why I thought it wasn’t an issue anymore as it was closed.

In my case I had jest and ts-jest both installed in 27.x.x, but an old version of react-scripts was referencing v26 which caused the issue:

2022-03-21_10-40-22

Reverting from 27.x to 26.5.6 resolved the problem for me.

Clearing cache and re-installing node modules did not.

Exactly the same here, clear cache, re-installing node_modules, another developer checking out on fresh machine, no cigar. Downgrading worked first time.

@asohail-futu check the version of jest you are using. In my case the issue was that I was using jest v26 with ts-jest v27. I was not installing jest directly, it was a dependency from Create React App. Maybe you are having the same issue!

fixed by upgrading jest to ^27.2.1 for me

Clearing cache & reinstalling did not help me, but upgrading jest-cli to ^27.2.1 did.

there is never a compatibility support before. Major version of ts-jest always follows Jest major version.

how about remove node_modules and reinstall? I think Jest is reading ts-jest from another dependency not direct dependency.

Please make sure that there are no other dependencies using ts-jest 26, otherwise Jest will keep loading that version instead of your direct ts-jest 27 dep.