To fix "cannot find module ‘ts-jest/utils’" error with Jest and TypeScript, we install the ts/jest
package.
To install it, we run
npm i -D jest typescript
npm i -D ts-jest @types/jest
to install the typescript
and ts-jest
modules with NPM.
typescript
is a prerequisite for the ts-jest
module.
Then we create a Jest config with
npx ts-jest config:init
Then we run tests with
npm test
or
npx jest
With Yarn, we run
yarn add --dev jest typescript
yarn add --dev ts-jest @types/jest
to install the packages.
We run
yarn ts-jest config:init
to create the Jest config.
And we run
yarn test
or
yarn jest
to run the tests.