Karma / webpack TypeError:无法读取属性' configPath'未定义的

时间:2017-09-21 11:32:17

标签: webpack karma-runner

运行karma.config.js时出现以下错误:

  

[karma]:TypeError:无法读取属性' configPath'未定义的       在D:\ View \ node_modules \ karma-webpack-preprocessor \ index.js:39:50       在nextPreprocessor(D:\ View \ node_modules \ karma \ lib \ preprocessor.js:36:26)       在D:\ View \ node_modules \ karma \ lib \ preprocessor.js:122:9       在module.exports(D:\ View \ node_modules \ isbinaryfile \ index.js:28:12)       在D:\ View \ node_modules \ karma \ lib \ preprocessor.js:84:7       在D:\ View \ node_modules \ graceful-fs \ graceful-fs.js:78:16       在FSReqWrap.readFileAfterClose [as oncomplete](fs.js:504:3)

我的karma.config.js看起来像这样:

var webpackConfig = require('./webpack.config.js');
webpackConfig.entry = {};

module.exports = function(config) {
    config.set({
        basePath: '',
        frameworks: ['jasmine'],

        reporters: ['progress'],
        port: 9876,
        colors: false,
        logLevel: config.LOG_INFO,
        autoWatch: false,
        browsers: ['Chrome'],
        singleRun: false,
        autoWatchBatchDelay: 300,

        files: [
            './src/index.js',
            './**/*.spec.js'],

        preprocessors: {
            './src/index.js': ['webpack'],
            '.**/*.spec.js': ['babel']
        },

        webpack: webpackConfig,

        webpackMiddleware: {
            noInfo: true
        }
    });
}

我尝试在karma.config.js中引用的webpack配置完全正常,当我单独使用webpack时。

那么这可能是什么问题?

1 个答案:

答案 0 :(得分:0)

我发现我的节点模块中有karma-webpack-preprocessorkarma-webpack。它们使用相同的预处理程序名称'webpack'

要卸载karma-webpack-preprocessor并保持karma-webpack对我有用。

你也可以保留karma-webpack-preprocessor,但是像这样定义configPath:

webpackPreprocessor: {
  configPath: './config/webpack'
},

你可以在这里看到: https://www.npmjs.com/package/karma-webpack-preprocessor