Reputation: 1064
I have already installed Jest in my React project. I even installed jest-cli, but still can't use Jest in the command line. I can do an npm test, as it is in my package.json, but I have problems with the test, and in order to fix it I need to access the 'jest' command. (I need to run jest --init
and to create the config file.) Thank you in advance!
Upvotes: 42
Views: 83037
Reputation: 1
I was facing the same issue for my nodejs project. I digged around, and found that my yarn.lock and package-lock.json are not in sync. I might have mistakenly used npm for adding package while i was using yarn for everything else. So when i started work on a new system , jest package was missing in devDependencies. I ran yarn,but of course jest was not installed. Before someone start pointing we should have only one lock file, i am already aware of it, it was just petty mistake.
Upvotes: 0
Reputation: 1
Use npx to solve the error "jest: command not found", e.g. npx jest or install the package globally by running npm install -g jest to be able to use the command without the npx prefix.
Upvotes: 0
Reputation: 1840
Try installing jest as a dev dependency.
npm install --save-dev jest
Then run it with npm test
, (Edit the package.json
file if necessary to add the script). Don't use jest
command directly. It's not recommended.
If you want to use jest
command use node_modules/.bin/jest
.
Upvotes: 70
Reputation: 164
You can use "node_modules\.bin\jest" --init
if you are on Windows.
Upvotes: 10
Reputation: 506
the problem got fixed when I installed it globally as an Admin (right-click CMD and run as admin) with the below command
npm install -g jest
then go to the test file and do a jest on it.
Upvotes: 1
Reputation: 560
I fixed this problem only after installing jest globally:
npm install -g jest
Upvotes: 46