Webpack 2 2.2.0-rc.4 throws error in test setup

I am putting together a project boilerplate using Webpack 2. I set up unit tests using a Karma/Mocha/Phantom stack and got everything working. I nuked my node_modules and the tests started throwing an error. I traced the issue to the webpack update from 2.2.0-rc.3 to 2.2.0-rc.4. Under 2.2.0-rc.3 everything continues to work as expected but the upgrade to 2.2.0-rc.4 throws.

I can see the error is saying i don’t have and entry key in my webpack config. If i add an entry file using the test bundle (entry: 'test/tests.bundle.js',) the tests run but webpack logs an error in the test output which is not ideal. I don’t know if this is a bug or if a non-backwards compatible API change has been implemented. If the latter, any pointers on how to fix without logging errors would be gratefully received:

Error thrown by starting tests without an entry key:

11 01 2017 17:40:36.434:ERROR [preprocess]: Can not load "webpack"!
  WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.entry should be one of these:
   object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function
   The entry point(s) of the compilation.
   Details:
    * configuration.entry should NOT have less than 1 properties ({
        "keyword": "minProperties",
        "dataPath": ".entry",
        "schemaPath": "#/oneOf/0/minProperties",
        "params": {
          "limit": 1
        },
        "message": "should NOT have less than 1 properties",
        "schema": 1,
        "parentSchema": {
          "minProperties": 1,
          "additionalProperties": {
            "oneOf": [
              {
                "description": "The string is resolved to a module which is loaded upon startup.",
                "minLength": 1,
                "type": "string"
              },
              {
                "description": "All modules are loaded upon startup. The last one is exported.",
                "$ref": "#/definitions/common.nonEmptyArrayOfUniqueStringValues"
              }
            ]
          },
          "description": "Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.",
          "type": "object"
        },
        "data": {}
      }).
      object { <key>: non-empty string | [non-empty string] }
      Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.
    * configuration.entry should be a string.
    * configuration.entry should be an array:
      [non-empty string]
    * configuration.entry should be an instance of function
      function returning an entry object or a promise..
    at webpack (/Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/webpack/lib/webpack.js:19:9)
    at new Plugin (/Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/karma-webpack/lib/karma-webpack.js:63:18)
    at invoke (/Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/di/lib/injector.js:75:15)
    at Array.instantiate (/Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/di/lib/injector.js:59:20)
    at get (/Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/di/lib/injector.js:48:43)
    at /Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/di/lib/injector.js:71:14
    at Array.map (native)
    at Array.invoke (/Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/di/lib/injector.js:70:31)
    at get (/Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/di/lib/injector.js:48:43)
    at instantiatePreprocessor (/Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/karma/lib/preprocessor.js:55:20)
    at Array.forEach (native)
    at createPreprocessor (/Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/karma/lib/preprocessor.js:74:20)
    at Array.invoke (/Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/di/lib/injector.js:75:15)
    at get (/Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/di/lib/injector.js:48:43)
    at /Users/fubar/Documents/Github-Projects/leanne1-webpack2/node_modules/di/lib/injector.js:71:14
    at Array.map (native)

START:
11 01 2017 17:40:36.510:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
11 01 2017 17:40:36.510:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
11 01 2017 17:40:36.512:ERROR [karma]: Found 1 load error

** test output with an entry key of test/tests.bundle.js**

START:
Hash: 3d8d278d187a42e101d2
Version: webpack 2.2.0-rc.4
Time: 597ms
               Asset   Size  Chunks             Chunk Names
test/tests.bundle.js  11 kB       0  [emitted]  test/tests.bundle.js
chunk    {0} test/tests.bundle.js (test/tests.bundle.js) 1.34 kB [entry] [rendered]
    [0] ./test .+\.spec\.jsx?$ 195 bytes {0} [built]
    [1] ./src/app/utils/add.js 471 bytes {0} [built]
    [2] ./test/unit/specs/utils/add.spec.js 306 bytes {0} [optional] [built]
    [3] ./test/tests.bundle.js 364 bytes {0} [built]

ERROR in Entry module not found: Error: Can't resolve 'test/tests.bundle.js' in '/Users/fubar/Documents/Github-Projects/leanne1-webpack2'
11 01 2017 17:46:43.941:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
11 01 2017 17:46:43.946:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
11 01 2017 17:46:43.969:INFO [launcher]: Starting browser PhantomJS
11 01 2017 17:46:46.413:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#F75F8TAqEXcj-S_sAAAA with id 13234629
  Testing test setup using add util
     should add two numbers together

Finished in 0.009 secs / 0 secs

SUMMARY:
 1 test completed
----------|----------|----------|----------|----------|----------------|
File      |  %% Stmts | %% Branch |  %% Funcs |  %% Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
----------|----------|----------|----------|----------|----------------|
All files |      100 |      100 |      100 |      100 |                |
----------|----------|----------|----------|----------|----------------|

karma.conf.js

const TARGET = process.env.npm_lifecycle_event;
const isTdd = TARGET === 'test:tdd';

module.exports = function (config) {
	config.set({
		browsers: ['PhantomJS'],
		files: [
			'node_modules/phantomjs-function-bind-polyfill/index.js',
			'node_modules/phantomjs-polyfill/bind-polyfill.js',
			'node_modules/phantomjs-polyfill-includes/includes-polyfill.js',
			'node_modules/babel-es6-polyfill/browser-polyfill.js',
			'node_modules/whatwg-fetch/fetch.js',
			'test/tests.bundle.js'
		],
		frameworks: ['chai', 'mocha'],
		plugins: [
			'karma-webpack',
			'karma-phantomjs-launcher',
			'karma-chai',
			'karma-mocha',
			'karma-sourcemap-loader',
			'karma-mocha-reporter',
			'karma-coverage',
			'istanbul-instrumenter-loader',
		],
		preprocessors: {
			'test/tests.bundle.js': ['webpack', 'sourcemap']
		},
		reporters: ['mocha', 'coverage'],
		singleRun: !isTdd,
		coverageReporter: {
			reporters: [
				{ type: 'text' },
				{ type: 'html' }
			],
			dir: 'test/coverage/'
		},
		webpack: {
		       // entry: 'test/tests.bundle.js',
                       devtool: 'inline-source-map',
			module: {
				loaders: [
					{ test: /\.jsx?$/, loader: 'babel-loader' }
				]
			}
		},
		webpackMiddleware: {
			noInfo: true,
		}
	});
};

package.json

{
  "name": "webpack2",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server",
    "build": "NODE_ENV=production webpack -p",
    "test": "karma start",
    "test:tdd": "karma start"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel": "^6.5.2",
    "babel-cli": "^6.18.0",
    "babel-core": "^6.21.0",
    "babel-es6-polyfill": "^1.1.0",
    "babel-loader": "^6.2.10",
    "babel-preset-es2015": "^6.18.0",
    "babel-preset-react": "^6.16.0",
    "babel-preset-stage-0": "^6.16.0",
    "clean-webpack-plugin": "^0.1.15",
    "css-loader": "^0.26.1",
    "extract-text-webpack-plugin": "^2.0.0-beta.4",
    "html-webpack-plugin": "^2.26.0",
    "istanbul-instrumenter-loader": "^1.2.0",
    "karma": "^1.3.0",
    "karma-chai": "^0.1.0",
    "karma-chai-plugins": "^0.8.0",
    "karma-coverage": "^1.1.1",
    "karma-mocha": "^1.3.0",
    "karma-mocha-reporter": "^2.2.1",
    "karma-phantomjs-launcher": "^1.0.2",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^1.8.1",
    "less": "^2.7.2",
    "less-loader": "^2.2.3",
    "mocha": "^3.2.0",
    "phantomjs": "^2.1.7",
    "phantomjs-function-bind-polyfill": "^1.0.0",
    "phantomjs-polyfill": "0.0.2",
    "phantomjs-polyfill-includes": "^1.0.2",
    "postcss-loader": "^1.2.1",
    "react-hot-loader": "^3.0.0-beta.6",
    "style-loader": "^0.13.1",
    "webpack": "2.2.0-rc.4",
    "webpack-dev-server": "^2.2.0-rc.0",
    "webpack-merge": "^2.3.1"
  },
  "dependencies": {
    "normalize.css": "^5.0.0",
    "react": "^15.4.2",
    "react-dom": "^15.4.2",
    "whatwg-fetch": "^2.0.1"
  }
}

.babelrc

{
    "presets": [
        ["es2015", { "modules": false }],
        "stage-0",
        "react"
    ],
    "plugins": [
        "react-hot-loader/babel"
    ]
}

I’m running Node v5.10.1

The full repo can be viewed / cloned from here – the repo version is locked to webpack 2.2.0-rc.3 for which everything works fine, but you can replicate the issue/s by changing webpack to 2.2.0-rc.4:
https://github.com/leanne1/leanne1-webpack2
Tests are run up with npm run test

Author: Fantashit

2 thoughts on “Webpack 2 2.2.0-rc.4 throws error in test setup

  1. @johnnyreilly @TheLarkInn Yes – now running webpack v2.2.0-rc.4 and karma-webpack v2.0.1 and everything runs fine, with no entry key required in the webpack config of karma.conf.js. All fixed – thanks again for your help!

Comments are closed.