If you use AngularJS and install Karma (>0.10) and then run into the errorĀ ERROR [config]: Config file must export a function! here is a quick fix. The problem is caused by a recent change how Karma reads config files, but it’s an easy fix.

config/karma.conf.js

Open this file, it should look something like this,

// Contents of: config/karma.conf.js
basePath = '../';

files = [
  JASMINE,
  JASMINE_ADAPTER,
  'app/lib/angular/angular.js',
  'app/lib/angular/angular-*.js',
  'test/lib/angular/angular-mocks.js',
  'app/js/**/*.js',
  'test/unit/**/*.js'
];

autoWatch = true;

browsers = ['Chrome'];

junitReporter = {
  outputFile: 'test_out/unit.xml',
  suite: 'unit'
};

Replace these lines with the following,

// Contents of: config/karma.conf.js
module.exports = function (config) {
  config.set({
    basePath : '../',

    // Fix for "JASMINE is not supported anymore" warning
    frameworks : ["jasmine"],

    files : [
      'app/lib/angular/angular.js',
      'app/lib/angular/angular-*.js',
      'test/lib/angular/angular-mocks.js',
      'app/js/**/*.js',
      'test/unit/**/*.js'
    ],

    autoWatch : true,

    browsers : ['Chrome'],

    junitReporter : {
      outputFile : 'test_out/unit.xml',
      suite      : 'unit'
      //...
    }
  });
}

Job done! Try running your tests again, everything should work again.

Update: Thanks to a comment from Clare, the above code has now been modified further to remove the “WARN [config]: JASMINE is not supported anymore.” warning as well.


5 Comments » for Fixing “ERROR [config]: Config file must export a function!”
  1. Clare says:

    Legend! Thanks Also – with Karma v0.10.1 when I first ran my tests I also got ‘[WARN] config – JASMINE is not supported anymore.’ and [WARN] config – JASMINE_ADAPTER is not supported anymore. – fix for this here: http://yasuhiroyoshida.github.io/2013/05/20/jasmine-is-not-supported,-angular_scenario-is-not-supported,-and-econnrefused/

  2. Taimila says:

    Thanks! I wasn’t sure what was wrong with my setup.

  3. hari says:

    Thanks Very much. Nice Post.

  4. Alan says:

    Very nice. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*