jest: getVersion is not defined

🐛 Bug Report

Jest v24 crashes with “getVersion” is not defined.

To Reproduce

See source code.

Expected behavior

Jest does not crash.

Issue in source

This line requires cli. But cli itself requires jest here. Clearly, getVersion is not exported at this point.

Run npx envinfo --preset jest

Paste the results here:

System:
    OS: Windows 10
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Yarn: 1.10.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 10
  • Comments: 37 (18 by maintainers)

Commits related to this issue

Most upvoted comments

@eliw00d @hediet workaround before new release:

// Preload `cli` to avoid cyclical dependency
require('jest-cli/build/cli');

require('jest').run(...);

24.1.0 is released

I’m running into this same error but only when running jest programmatically (require('jest').run(argv)). When I yarn jest it works fine.

I kinda don’t wanna rush anyone, but maybe it’s time to let it go with version 24.0.1 🛸

#7707 fixes this issue. #7696 will probably land soonish, proper programmatic API… I don’t know. Maybe 25? 🙂 I’ll open up an issue for it requesting feedback

Battlefield news: 📰

I have managed to start Jest by adding those lines into the scripts/test.js:

// jest v24.0 workaround
require('jest/node_modules/jest-cli/build/cli');
require('jest').run(argv);

After, when I’m start Jest to run all over the tests, it shows this:

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In C:\<projectPath>
  49 files checked.
  testMatch: <projectPath>/src/**\?(*.)(spec|test).{js,jsx,ts,tsx} - 0 matches
  testPathIgnorePatterns: \\node_modules\\ - 49 matches
  testRegex:  - 49 matches
Pattern:  - 0 matches

Unable to locate any of the test files. 🔍

The fix #7707 is not yet released.

Ah, ok. We need #7696 😅

I’ll put together a PR

I’m running into this same error but only when running jest programmatically (require('jest').run(argv)). When I yarn jest it works fine.

Thank you, we also run it programmatically. That seems to be it.

Not sure what’s happening, but one thing that’s bitten me before is mismatching jest installations.

Make sure to not have both jest and jest-cli installed at the same time (you just need jest), and that you’re not using CRA (CRA ships with its own version of Jest, so you shouldn’t update it yourself 🙂)

I can’t repro the error. Can you share what you executed when it crashed?