Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

The shell says 'jest: command not found'

Errorcommand not found: jest

Short answer

Your shell only finds programs on its PATH, and a Jest installed in the project lives in node_modules, which is not on it. Run it through an npm script or npx, install Jest in the project if it is missing, or install it globally if you really want the bare jest command.

  • Applies to Jest 29, npm 10, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether the project has Jest installed and whether package.json has a test script.

    npm ls jest
    grep -n "\"test\"" package.json
  2. 2Match what you see, then jump to its fix

    1. 1npm ls jest lists a version, yet the bare jest command is not foundYou typed jest in the shell, but Jest is only installed in the projectFix
    2. 2npm ls jest shows (empty)Jest is not installed in the projectFix
    3. 3You run Jest on many projects and prefer typing jestYou want the bare jest command everywhereFix
    4. 4npx jest prompts to install a package, or downloads onenpx cannot find the binary it should runFix

What does the error look like?

  • command not found: jest
  • zsh: command not found: jest
  • jest: command not found

Cause 1 of 4

You typed jest in the shell, but Jest is only installed in the project

1Check

Locally installed binaries are not on your shell PATH. They are added to PATH when npm runs a script, and npx also finds them.

npm ls jest
ls node_modules/.bin | grep jest

2Fix

Run Jest through the project: with the test script, or with npx. Extra flags go after a double dash.

npm test
npm run test -- --watchAll=false
npx jest

3Verify

Jest prints a PASS or FAIL summary instead of the shell error.

npm test

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 4

Jest is not installed in the project

1Check

Cloning a repo without running an install, or a template that never listed Jest, leaves nothing to run.

npm ls jest
ls node_modules | head -n 3

2Fix

Add Jest as a dev dependency and give package.json a test script that runs it.

npm install --save-dev jest

// package.json
"scripts": {
  "test": "jest"
}

3Verify

npm test now starts Jest.

npm test

Confirmed by jestjs.io

Did this fix it?

Cause 3 of 4

You want the bare jest command everywhere

1Check

The Jest docs say the jest command must be on your PATH to run it directly, for example through a global install.

which jest

2Fix

Install Jest globally. A global copy can differ from a project's version, so prefer npx jest inside projects.

npm install jest --global

3Verify

The shell finds the command.

jest --version

Confirmed by jestjs.io

Did this fix it?

Cause 4 of 4

npx cannot find the binary it should run

1Check

When a package is not in the project, npx fetches it into the npm cache and asks first. That means local Jest is missing, so the previous cause applies.

npx --no jest --version

2Fix

Install Jest in the project, then run npx jest again. Use --no to stop npx from downloading anything.

npm install --save-dev jest
npx --no jest --version

3Verify

The command prints a version number from the local install.

npx --no jest --version

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Always run project tools through npm scripts so everyone uses the same version.
  • Run npm install right after cloning a repo.
  • Keep a test script in package.json, even when the team uses npx.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.