diff --git a/src/karma-webpack.js b/src/karma-webpack.js index 33bc1e2..3192895 100644 --- a/src/karma-webpack.js +++ b/src/karma-webpack.js @@ -2,7 +2,8 @@ no-param-reassign, no-console, no-shadow, - func-names + func-names, + import/no-dynamic-require */ const os = require('os'); @@ -12,7 +13,12 @@ const cloneDeep = require('clone-deep'); const async = require('neo-async'); const webpack = require('webpack'); const WebpackDevMiddleware = require('webpack-dev-middleware'); -const SingleEntryDependency = require('webpack/lib/dependencies/SingleEntryDependency'); + +const isWebpack4 = webpack.version[0] === '4'; +const dependencyPath = isWebpack4 ? + 'webpack/lib/dependencies/SingleEntryDependency': + 'webpack/lib/dependencies/EntryDependency'; +const SingleEntryDependency = require(dependencyPath); let blocked = []; let isBlocked = false; @@ -300,11 +306,12 @@ Plugin.prototype.make = function(compilation, callback) { compilation.addEntry('', dep, name, (err) => { // If the module fails because of an File not found error, remove the test file + const module = isWebpack4 ? dep.module : compilation.moduleGraph.getModule(dep); if ( - dep.module && - dep.module.error && - dep.module.error.error && - dep.module.error.error.code === 'ENOENT' + module && + module.error && + module.error.error && + module.error.error.code === 'ENOENT' ) { this.files = this.files.filter((f) => file !== f); invalidate(this.middleware);