Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Jest: a transform must export something. #2612

Closed
DarkLite1 opened this issue May 25, 2021 · 29 comments
Closed

TypeError: Jest: a transform must export something. #2612

DarkLite1 opened this issue May 25, 2021 · 29 comments
Labels
Not An Issue Not ts-jest issue

Comments

@DarkLite1
Copy link

🐛 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

@DarkLite1 DarkLite1 added Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels May 25, 2021
@silverbucket
Copy link

Getting the same error. sockethub/sockethub#429

$ cat jest.config.js
module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  coverageThreshold: {
    global: {
      branches: 75,
      functions: 80,
      lines: 90,
      statements: 90,
    },
  },
  coverageReporters: [
    'json',
    'lcov',
    'text',
    'clover',
  ]
};

Package versions:

    "@types/jest": "26.0.23",
    "jest": "27.0.1",
    "ts-jest": "26.5.6",

@ahnpnl
Copy link
Collaborator

ahnpnl commented May 25, 2021

duplicate #2611

@ahnpnl ahnpnl closed this as completed May 25, 2021
@ahnpnl ahnpnl added Not An Issue Not ts-jest issue and removed Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels May 25, 2021
@DarkLite1
Copy link
Author

DarkLite1 commented May 25, 2021

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.

@covertbert
Copy link

So which is the issue that's actually tracking this as both this and the linked one are closed? I've just upgraded to 27.0.1 and I'm getting this error

@ahnpnl
Copy link
Collaborator

ahnpnl commented May 26, 2021

pls clear Jest cache and use ts-jest 27.0.0

@covertbert
Copy link

That worked, thank you!

@igauravsehrawat
Copy link

Thanks. Saved the day!

@Jeff-Tian
Copy link

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

@ahnpnl
Copy link
Collaborator

ahnpnl commented May 28, 2021

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

@PhiLhoSoft
Copy link

Also reverted, because I don't use ts-jest, but @angular-builders/jest. Will wait to switch to Angular 12 before updating this one.

@asohail-futu
Copy link

Still getting this issue even after clearing the jest cache and updating ts-jest to 27.0.1.
Is there any other step that needs to be done?

@ahnpnl
Copy link
Collaborator

ahnpnl commented May 28, 2021

You should clear Jest cache via jest —clearCache

@asohail-futu
Copy link

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

@asohail-futu
Copy link

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.

@ahnpnl
Copy link
Collaborator

ahnpnl commented May 28, 2021

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.

@asohail-futu
Copy link

btw, thank you so much for your quick replies and all your work with ts-jest!

I already tried doing a clean install of node_modules and upon your suggestion looked through the versions of ts-jest being used in package-lock – only v27 is being used.

@sauldeleon
Copy link

@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!

@asohail-futu
Copy link

Thanks for the suggestion @sauldeleon but the issue still occurred while using jest v27 and no other dependency was using v26, as far as I could check. For now, I've reverted back to v26.

@sauldeleon
Copy link

@asohail-futu are you using react-scripts? in my case just check .lock file and see if any subdependant library is using jest 26. I had to use yarn resolutions feature to force react-scripts to use also jest 27.

I have also reverted to jest 26, but if you need jest 27 you can try that workarround

pjanik added a commit to concord-consortium/tectonic-explorer that referenced this issue Jun 29, 2021
v27 was causing some issues that don't seem to have an easy workaround yet: kulshekhar/ts-jest#2612
yuichielectric added a commit to octodemo/pr-gatekeeper that referenced this issue Jul 1, 2021
Running tests failed after updating jest to over 27.0.0 because of the issue described here:
kulshekhar/ts-jest#2612

To fix this issue, we need to update js-test as well.
akash1810 added a commit to guardian/cdk that referenced this issue Jul 1, 2021
@Xaz16
Copy link

Xaz16 commented Jul 5, 2021

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.

I don't want to use jest 27 due to we have in issue with raised memory usage in this version (#2696). Does it mean that backward compatibility is broken?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jul 5, 2021

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

@Xaz16
Copy link

Xaz16 commented Jul 5, 2021

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

Ok, got it. It is hard to understand, because now I'm in situation when all pipelines is down, but ok.
When can we wait for fix of that one? #2696

@michaeleliot
Copy link

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.

@hansiemithun
Copy link

hansiemithun commented Aug 3, 2021

And this fix is leading to: TypeError: Cannot read property 'bind' of undefined. runtime.setGlobalsForRuntime is undefined now.

Reference: jestjs/jest#11720

cristiangreco added a commit to gradle-update/update-gradle-wrapper-action that referenced this issue Aug 8, 2021
@samuelneff
Copy link

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

Clearing cache and re-installing node modules did not.

TomJKing added a commit to nationalarchives/tdr-transfer-frontend that referenced this issue Aug 31, 2021
Dependabot Jest upgrade PR cause all tests to fail

Manually do upgrade with fix for Jest tests:
- 'ts-jest' version required upgrade: kulshekhar/ts-jest#2612 (comment)
- Add 'testEnvironment' to Jest config: https://stackoverflow.com/questions/67373953/jest-fails-with-self-is-not-defined-when-importing-react-diagrams
@cmcnicholas
Copy link

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.

@karol-majewski
Copy link

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

@whatwewant
Copy link

fixed by upgrading jest to ^27.2.1 for me

@zirkelc
Copy link

zirkelc commented Mar 21, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not An Issue Not ts-jest issue
Projects
None yet
Development

No branches or pull requests