【问题标题】:Grunt + Karma test runner fails with "ReferenceError: module is not defined"Grunt + Karma 测试运行器因“ReferenceError:未定义模块”而失败
【发布时间】:2013-12-30 18:24:57
【问题描述】:

当通过 Grunt 运行我们的 Karma 测试时,执行失败并出现以下错误:

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

Gruntfile.js 中的 Karma 配置看起来很正常,我从另一个项目中复制了它,它工作得很好。 karma.conf.js 文件相同,与其他项目之一没有区别,它可以正常工作。

我看过这个问题,但对解决问题没有帮助:Testing service in Angular returns module is not defined

我没有粘贴 Grunt 或 Karma 配置文件,因为它们对解决此问题没有任何影响。

【问题讨论】:

    标签: angularjs gruntjs karma-runner


    【解决方案1】:

    在此处找到此问题的解决方案:https://github.com/karma-runner/grunt-karma/issues/52

    基本上,grunt-karma 模块的旧版本被用作 dev 依赖项,在这种情况下它是版本 0.4.3 - 这是一个 sn-p来自package.json 文件:

    {
      "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"
      },
    
      // ...
    }
    

    显然,这个旧版本的 grunt-karma 导致了 module is not defined 错误。

    更新它以使用更新的版本(0.6.2,我们在另一个运行良好的项目中使用它)解决了这个问题:

    "grunt-karma": "~0.6.2"
    

    然后在项目目录下运行npm install,下载了grunt-karma的更新版本,之后测试运行良好。

    【讨论】:

      猜你喜欢
      • 2021-10-08
      • 2018-05-05
      • 2019-07-09
      • 2015-11-18
      • 2014-07-03
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 1970-01-01
      相关资源
      最近更新 更多