Last updated: Mar 7, 2024
Reading timeยท3 min

process functionThe 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.
npm list jest --depth=0 npm list ts-jest --depth=0

Notice that jest and ts-jest are both version 29 in my case.
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.
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.
npm install --save-dev jest@29 ts-jest@29 --legacy-peer-deps
You can also update your global jest module to the same version.
npm install -g jest@29
Try to clear your jest cache after installing the same major version for both packages.
npx jest --clearCache

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.
npm install --save-dev jest@latest ts-jest@latest
If you get an error, rerun the command with the --force flag.
npm install --save-dev jest@latest ts-jest@latest --force
You should also update your global jest module to the latest version.
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.
npx jest --clearCache

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.
# 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.
# 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.
If the error persists, check if other packages reference older versions of
jest or ts-jest by issuing the following commands.
npm list jest npm list ts-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.
npm install react-scripts@latest
Try to clear your jest cache if the issue persists.
npx jest --clearCache
You can learn more about the related topics by checking out the following tutorials:
process function