nwinkler
nwinkler

Reputation: 54437

Grunt + Karma test runner fails with "ReferenceError: module is not defined"

When running our Karma test through Grunt, the execution fails with the following error:

[2013-12-30 10:14:22.690] [ERROR] config - Invalid config file!
[ReferenceError: module is not defined]

The Karma configuration in Gruntfile.js looks sane, I've copied it from another project, where it works just fine. Same for the karma.conf.js file, there's no difference to one of the other projects, where it works fine.

I've had a look at this question, but it didn't help with fixing the issue: Testing service in Angular returns module is not defined

I'm not pasting the Grunt or Karma config files since they didn't have any impact on fixing this issue.

Upvotes: 2

Views: 4109

Answers (1)

nwinkler
nwinkler

Reputation: 54437

The solution for this issue was found here: https://github.com/karma-runner/grunt-karma/issues/52

Basically, an old version of the grunt-karma module was used as a dev dependency, in this case it was version 0.4.3 - here's a snippet from the package.json file:

{
  "dependencies": {},
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-copy": "~0.4.1",
    "grunt-contrib-concat": "~0.3.0",
    "grunt-contrib-uglify": "~0.2.5",
    "grunt-karma": "~0.4.3",
    "matchdep": "~0.1.2",
    "karma": "~0.10.2",
    "karma-coverage": "~0.1.0",
    "karma-script-launcher": "~0.1.0",
    "karma-firefox-launcher": "~0.1.0",
    "karma-chrome-launcher": "~0.1.0",
    "karma-html2js-preprocessor": "~0.1.0",
    "karma-jasmine": "~0.1.3",
    "karma-requirejs": "~0.1.0",
    "karma-coffee-preprocessor": "~0.1.0",
    "karma-phantomjs-launcher": "~0.1.0",
    "karma-junit-reporter": "~0.1.0"
  },

  // ...
}

Apparently, this older version of grunt-karma is causing the module is not defined error.

Updating this to use a more recent version (0.6.2, which we use in the other project that's working fine) solved the issue:

"grunt-karma": "~0.6.2"

Then running npm install in the project directory downloaded the updated version of grunt-karma, and the tests ran fine after that.

Upvotes: 5

Related Questions