The shell says 'jest: command not found'
command not found: jestShort 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.
Fix it fast
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.json2Match what you see, then jump to its fix
- 1
npm 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
npm ls jest shows (empty)Jest is not installed in the projectFix - 3
You run Jest on many projects and prefer typing jestYou want the bare jest command everywhereFix - 4
npx jest prompts to install a package, or downloads onenpx cannot find the binary it should runFix
- 1
What does the error look like?
command not found: jestzsh: command not found: jestjest: 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 jest2Fix
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 jest3Verify
Jest prints a PASS or FAIL summary instead of the shell error.
npm testConfirmed by docs.npmjs.com
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 32Fix
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 testConfirmed by jestjs.io
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 jest2Fix
Install Jest globally. A global copy can differ from a project's version, so prefer npx jest inside projects.
npm install jest --global3Verify
The shell finds the command.
jest --versionConfirmed by jestjs.io
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 --version2Fix
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 --version3Verify
The command prints a version number from the local install.
npx --no jest --versionConfirmed by docs.npmjs.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
npm start fails because react-scripts is not found
react-scripts: command not found
npm runs scripts with node_modules/.bin on the PATH.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fix