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:
- Created 5 years ago
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What solved for me was the path to babel-jest in the “transform” key inside the jest.config.js file -
Change it to:
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?