98

When I run the command grunt I get the following warning:

Running "karma:unit" (karma) task
Warning: No provider for "framework:jasmine"! (Resolving: framework:jasmine) Use --force to continue.

Does anybody know how to resolve this issue?

0

6 Answers 6

181

I had the same error after creating a new project the yeoman angular generator (yo angular).

The solution for me was adding "karma-jasmine" to the devDependencies in packages.json and running "npm install" again.

npm install karma-jasmine --save-dev

This solved the error message "No provider for “framework:jasmine”!"

I also had to add a karma browser launcher to the devDependencies, as I got the message that no launcher was installed (see http://karma-runner.github.io/0.10/config/browsers.html).

npm install karma-safari-launcher --save-dev

My packages.json looked like this after my action:

{
  "name": "test1",
  "version": "0.0.0",
  "dependencies": {},
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-autoprefixer": "~0.4.0",
    "grunt-bower-install": "~0.7.0",
    "grunt-concurrent": "~0.4.1",
    "grunt-contrib-clean": "~0.5.0",
    "grunt-contrib-coffee": "~0.7.0",
    "grunt-contrib-compass": "~0.6.0",
    "grunt-contrib-concat": "~0.3.0",
    "grunt-contrib-connect": "~0.5.0",
    "grunt-contrib-copy": "~0.4.1",
    "grunt-contrib-cssmin": "~0.7.0",
    "grunt-contrib-htmlmin": "~0.1.3",
    "grunt-contrib-imagemin": "~0.3.0",
    "grunt-contrib-jshint": "~0.7.1",
    "grunt-contrib-uglify": "~0.2.0",
    "grunt-contrib-watch": "~0.5.2",
    "grunt-google-cdn": "~0.2.0",
    "grunt-newer": "~0.5.4",
    "grunt-ngmin": "~0.0.2",
    "grunt-rev": "~0.1.0",
    "grunt-svgmin": "~0.2.0",
    "grunt-usemin": "~2.0.0",
    "jshint-stylish": "~0.1.3",
    "load-grunt-tasks": "~0.2.0",
    "time-grunt": "~0.2.1",
    "karma-ng-scenario": "^0.1.0",
    "grunt-karma": "^0.8.0",
    "karma": "^0.12.0",
    "karma-jasmine": "~0.2.2",
    "karma-safari-launcher": "~0.1.1",
    "karma-ng-html2js-preprocessor": "^0.1.0"
  },
  "engines": {
    "node": ">=0.8.0"
  },
  "scripts": {
    "test": "grunt test"
  }
}

I changed the following line in karma.conf en karma-e2e.conf to use the karma-safari-launcher:

browsers: ['Safari'],

I hope this will work for you, too.

5
  • 2
    Thanks! The only thing I did different was that I used chrome npm install karma-chrome-launcher --save-dev
    – Luciano
    Apr 9, 2014 at 18:54
  • 1
    @KyleHayes Here is the bug report in the generator-angular project: github.com/yeoman/generator-angular/issues/629
    – cjerdonek
    Jun 12, 2014 at 22:04
  • 1
    I got Error: No provider for "framework:karma-chrome-launcher"! after this
    – David
    Sep 29, 2015 at 21:32
  • 1
    If you have plugins: [...] added to karma.config.js, then installing karma-jasmine will not solve the issue. you have to add 'karma-jasmine' to plugins array like plugins: ['karma-jasmine']. Mar 4, 2016 at 10:39
  • As per my understanding "npm install karma-jasmine --save-dev" was not having any effect on package.json. So Thanks for this solution.
    – Andy
    Apr 12, 2016 at 3:39
37

As @Taco said, the default solution for this problem is installing the appropriate plugin, like this: npm install karma-jasmine --save-dev or this: npm install karma-mocha --save-dev.

However, this error is also expected when you are running an old version of karma-cli because they updated the way karma loads the plugins. To make sure you have the latest version, run this:

npm install -g karma-cli
4
  • 1
    This fixed it for me. I had the dependencies previously mentioned, but karma-cli was out-of-date, apparently.
    – icfantv
    Aug 2, 2015 at 3:21
  • 1
    This fixed my problem. Thanks buddy
    – shaikh
    Sep 4, 2016 at 14:21
  • 1
    I ran into this too. Evidently, npm install -g karma is not the same thing as npm install -g karma-cli. Dec 27, 2016 at 14:18
  • @PeterMajeed After installing Jasmine, I thought maybe I could npm install -g karma but this does NOT work. You must use npm install -g karma-cli
    – Cobertos
    Jan 24, 2018 at 21:58
34

My problem was in my karma.config.js file:

plugins: [require("karma-webpack")]

This caused the other karma-* plugins not to be loaded, which includes karma-jasmine.

1
  • 1
    aleclarson's was also my problem. Since karma-webpack was already in my package.json's devDependencies, I commented out this plugins entry in my karma.config.js file. Oct 7, 2016 at 18:56
32

If your karma.conf.js specifies a plugins attribute, be sure to add karma-jasmine to the list. If all the plugins are prefixed with karma-, you don't need to specify this attribute as the plugins will be automatically loaded.

2
  • 6
    Thanks, this resolved my issue, adding karma-jasmine to the plugins!
    – sandip
    Dec 10, 2015 at 9:16
  • Thanks this worked - this is the full line. plugins: ['karma-jasmine', 'karma-chrome-launcher', 'karma-spec-reporter', 'karma-coverage'], Nov 8, 2017 at 6:11
6

It happened to me because I had Karma installed globally, and when I ran karma start command it actually ran in /usr/... rather than my dev directory.

In my case the solution was to remove karma and install karma-cli instead.

npm remove -g karma
npm install -g karma-cli
2

My problem was the selected "Karma package" in the IntelliJ run configuration. I did not select the project's karma package in the project's "node_module" folder: enter image description here

1
  • This is exactly what I was (missing) looking for.
    – vivekmore
    Sep 7, 2016 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.