TypeError Jest: a transform must export a `process` function

avatar
Borislav Hadzhiev

Last updated: Mar 7, 2024
3 min

banner

# TypeError Jest: a transform must export a process function

The error "TypeError: Jest: a transform must export a process function" occurs when your jest and ts-jest versions don't match.

To solve the error, make sure to install matching versions of jest and ts-jest because major versions of ts-jest always follow jest major versions.

Open your package.json file and check if the major versions of the jest and ts-jest packages in your devDependencies object differ.

For example, the error occurs if you use jest v26 with ts-jest v27.

You can also use the following commands to check your jest and ts-jest versions.

shell
npm list jest --depth=0 npm list ts-jest --depth=0

check jest and ts jest versions

Notice that jest and ts-jest are both version 29 in my case.

The major version (the digits before the first period) of ts-jest always follow jest major versions, so if yours diverge, the error occurs.

If you open the NPM pages of ts-jest and jest, you will see that the major versions match.

The major versions of both packages are 29 at the moment.

You can install a specific major version of jest and ts-jest by running the following command.

shell
npm install --save-dev jest@29 ts-jest@29

The command installs version 29 of both packages.

If you get an error when running the command, you might have to rerun it will the --legacy-peer-deps flag.

shell
npm install --save-dev jest@29 ts-jest@29 --legacy-peer-deps

You can also update your global jest module to the same version.

shell
npm install -g jest@29

Try to clear your jest cache after installing the same major version for both packages.

shell
npx jest --clearCache

clear jest cache

# Installing the latest version of jest and ts-jest

If the error persists, try to install the latest version of the jest and ts-jest packages.

Open your terminal in your project's root directory (where your package.json file is) and run the following command.

shell
npm install --save-dev jest@latest ts-jest@latest

If you get an error, rerun the command with the --force flag.

shell
npm install --save-dev jest@latest ts-jest@latest --force

You should also update your global jest module to the latest version.

shell
npm install -g jest@latest

If updating the module globally fails, you might have to prefix the command with sudo (macOS and Linux) or open Command Prompt as an administrator (Windows).

Try to clear your jest cache if the issue persists.

shell
npx jest --clearCache

clear jest cache

# Delete your node_modules and reinstall your dependencies

If the error persists, your node_modules might've glitched.

You might have other packages that depend on different versions of the jest and ts-jest modules.

If you are on macOS or Linux, run the following commands in bash or zsh to delete your node_modules folder.

shell
# for macOS and Linux rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐Ÿ‘‡๏ธ clean the cache npm cache clean --force npx jest --clearCache # ๐Ÿ‘‡๏ธ install packages npm install

If you are on Windows, run the following commands in CMD.

cmd
# for Windows rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐Ÿ‘‡๏ธ clean npm cache npm cache clean --force npx jest --clearCache # ๐Ÿ‘‡๏ธ install packages npm install

Try to restart your test server if the issue persists.

# Check if other packages reference older versions of jest or ts-jest

If the error persists, check if other packages reference older versions of jest or ts-jest by issuing the following commands.

shell
npm list jest npm list ts-jest

npm list jest

For example, the screenshot above shows that the react-scripts package references jest version 23.6.0.

You can try to update the packages that depend on older versions of jest and ts-jest.

Make sure to replace react-scripts with the output from issuing the 2 commands above.

shell
npm install react-scripts@latest

Try to clear your jest cache if the issue persists.

shell
npx jest --clearCache

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev