codymikol / karma-webpack

Karma webpack Middleware
MIT License
830 stars 222 forks source link

TypeError: Cannot read property 'name' of undefined in `mocha-env-loader.js` #326

Closed mfeineis closed 6 years ago

mfeineis commented 6 years ago

I'm submitting a bug report

Webpack version: 4.8.1

Webpack Karma version: 3.0.0

Karma version: 1.7

Please tell us about your environment: Ubuntu 17.04 64bit

Browser: doesn't matter

Current behavior: The mocha-env-loader still uses the this.options API which was deprecated in webpack@3 which has been removed in webpack@4. So I'm getting TypeError: Cannot read property 'name' of undefined errors when trying to use my own webpack config.

Expected/desired behavior: Plugins should get their options via this.query -> Migration guide

Running my tests with the babel-loader@7.1.2 plugin results in this error:

ERROR in ./test/basicTest.js (./node_modules/karma-webpack/lib/mocha-env-loader.js!./test/basicTest.js)
    Module build failed: TypeError: Cannot read property 'name' of undefined
        at Object.module.exports (/path-to-project/node_modules/karma-webpack/lib/mocha-env-loader.js:19:24)

This line seems to fix the problem, although this was just a quick try:

var id = this.query.id;//this.options.name;

My karma configuration

{
  "autoWatch": false,
  "basePath": "",
  "browsers": [
    "Chrome"
  ],
  "browserNoActivityTimeout": 30000,
  "colors": true,
  "concurrency": null,
  "exclude": [],
  "files": [
    "test/**/*Test.js"
  ],
  "frameworks": [
    "mocha",
    "sinon-chai"
  ],
  "port": 9876,
  "singleRun": true,
  "webpackMiddleware": {
    "stats": "errors-only"
  },
  "preprocessors": {
    "test/**/*Test.js": [
      "webpack",
      "sourcemap"
    ]
  },
  "webpack": {
    "devtool": "inline-source-map",
    "node": {
      "net": "empty",
      "fs": "empty"
    },
    "resolve": {
      "extensions": [
        ".js"
      ]
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: [/node_modules/],
                use: ['babel-loader']
            },
        ],
    },
    "mode": "development"
  },
  "plugins": [
    "karma-mocha",
    "karma-sinon-chai",
    "karma-webpack",
    "karma-chrome-launcher",
    "karma-mocha-reporter",
    "karma-sourcemap-loader"
  ],
  "reporters": [
    "mocha"
  ],
  "logLevel": "INFO"
}
mfeineis commented 6 years ago

Somebody out there? It's a single line change basically...

ryanclark commented 6 years ago

Fixed in v4.0.0-rc.0