question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest cannot use ts-jest when installed globally

See original GitHub issue

🐛 Bug Report

I can run tests with a local install…

npm install --save-dev jest ts-jest typescript

But a global install causes this error when jest is executed:

● Validation Error:
  Module ts-jest in the transform option was not found.

(This occurs even if ts-jest, but not jest, is installed locally in the project.)

To Reproduce

  • Run these terminal commands (including install of babel-core to avoid a “peer dependency” warning):

      mkdir temp
      cd temp
      npm init -f
      npm install --global jest ts-jest typescript babel-core
    
  • Add package.json configuration for ts-jest:

    "jest": {
      "transform": {
        "^.+\\.tsx?$": "ts-jest"
      },
      "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
      "moduleFileExtensions": ["ts","tsx","js","jsx","json"]
    }
    
  • Run jest to get “Module ts-jest in the transform option was not found.”

Expected behavior

If the error does not occur, the output is “No tests found”

Run npx envinfo --preset jest

npx: installed 1 in 2.921s

  System:
    OS: Windows 10
    CPU: x64 Intel(R) Core(TM) i5 CPU         750  @ 2.67GHz
  Binaries:
    npm: 6.1.0 - C:\Program Files\nodejs\npm.CMD

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

6reactions
chenopcommented, Jul 17, 2019

What solved for me was the path to babel-jest in the “transform” key inside the jest.config.js file -

transform: {
    "\\.js$": "../node_modules/babel-jest" 
}

Change it to:

transform: { . 
    "\\.js$": "<rootDir>/node_modules/babel-jest" // Use <rootDir> . 
 },  
3reactions
GeeWeecommented, Jul 12, 2018

Can you clarify @SimenB ? “Module ts-jest in the transform option was not found.” is definitely not an error that ts-jest is throwing. (I grepped our codebase to make sure) - are you sure this is not an error thrown by jest when it can’t find the specified preprocessor?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest is not recognized by typescript
Typescript simple shows a bunch of errors complaining it can't find jest , can't find describe (which is defined in jest). I tried...
Read more >
ts-jest
ts -jest. A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. NPM version NPM...
Read more >
Installing ts-jest - Huafu
You can install ts-jest and dependencies all at once with the following commands. Using npm : npm install --save-dev jest typescript ts-jest @types/jest....
Read more >
Configuring Jest
A global setup module configured in a project (using multi-project runner) will be triggered only when you run at least one test from...
Read more >
Jest and Typescript installation / configuration | Test
Typescript. Types. ts-jest. Support. SyntaxError: Cannot use import statement outside a module ... yarn global add jest # or npm npm install -g...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found