34

I am using Yeoman toolkit to bootstrap an Angular web application. I've followed all the steps mentioned here. But still, apparently, grunt can not find the karma module. It spits out this error:

Loading "grunt-karma.js" tasks...ERROR
>> Error: Cannot find module 'karma'
Warning: Task "karma" not found. Use --force to continue.

Aborted due to warnings.

I've tried installing karma both locally and globally using npm, but nothing seems to work.

TeknasVaruas
  • 1,480
  • 3
  • 15
  • 28

5 Answers5

71

Make sure you have installed both karma and grunt-karma before running the grunt task:

npm install karma
npm install grunt-karma

EDIT: One liner:

npm install karma grunt-karma
Abhishek Bedi
  • 5,205
  • 2
  • 36
  • 62
Stuart
  • 866
  • 1
  • 8
  • 7
  • 2
    I have the same problem, but this did not fix it for me. – skube Mar 19 '14 at 16:53
  • I just added this information. It's now in the ["Getting Started" guide](https://github.com/karma-runner/grunt-karma#getting-started) – dude Dec 11 '15 at 10:32
10

I had to install the following

  npm install phantomjs
  npm install jasmine-core
  npm install karma
  npm install grunt-karma

Goodluck, Rajesh

Edit: One liner:

npm install karma grunt-karma jasmine-core phantomjs
Abhishek Bedi
  • 5,205
  • 2
  • 36
  • 62
Rajesh Jain
  • 1,159
  • 3
  • 19
  • 37
5

This work for me:

npm install phantomjs jasmine-core jasmine karma grunt-karma

Node version: 4.2.2

d.danailov
  • 9,594
  • 4
  • 51
  • 36
  • In addition to what @d.danailov suggested, I also had to run: `npm install karma-jasmine karma-firefox-launcher karma-phantomjs-launcher karma-junit-reporter karma-html-reporter karma-coverage --save-dev` – posix99 Oct 09 '17 at 15:41
0

I had the exact same problem and running npm install karma fixed it temporarily too.

The issue though wasn't that karma hadn't been initialized but rather that the repository that we were using had node_modules checked in without karma's debug folder.

This was all because the .gitignore file was ignoring all the debug folders for checkins. Make sure your .gitignore file isn't ignoring things you want

Nate-Wilkins
  • 5,364
  • 4
  • 46
  • 61
0
npm install karma
npm install grunt-karma 

above command will fix the issue.

MathieuF
  • 3,130
  • 5
  • 31
  • 34