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

六月ゝ 毕业季﹏ 提交于 2020-02-04 05:11:05

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/20837584/grunt-karma-test-runner-fails-with-referenceerror-module-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!