Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR [preprocess]: Can not load "webpack"! ([email protected]; [email protected])

I try to get my karma tests running with webpack@^2.2.1 and [email protected]. But all i get is this Error:

ERROR [preprocess]: Can not load "webpack"!
  Error
    at webpack (/Users/plano/S/plano/projects/scheduler.frontend.ng2/node_modules/webpack/lib/webpack.js:19:9)
    at new Plugin (/Users/plano/S/plano/projects/scheduler.frontend.ng2/node_modules/karma-webpack/lib/karma-webpack.js:65:18)
    at invoke (/Users/plano/S/plano/projects/scheduler.frontend.ng2/node_modules/di/lib/injector.js:75:15)
    ...

All solutions that i found are about a bug in [email protected] (e.g. this github issue and this stackoverflow quertion). Im on 1.4.1 so they aren’t helpful for me.

This post tells me to remove entry: {} from webpack config. I have no entry: {} on my webpack config.

According to this stackoverflow answer it’s an webpack issue since 2.2.0-rc.4. So i tried 2.2.0-rc.3. Nothing changed.

My karma.conf.js:

'use strict';

module.exports = config => {
    config.set({
        autoWatch: true,
        browsers: ['Chrome', 'PhantomJS'],
        files: [
            '../node_modules/es6-shim/es6-shim.min.js',
            'karma.entry.js'
        ],
        frameworks: ['jasmine'],
        logLevel: config.LOG_INFO,
        phantomJsLauncher: {
            exitOnResourceError: true
        },
        port: 9876,
        preprocessors: {
            'karma.entry.js': ['webpack', 'sourcemap']
        },
        reporters: ['dots'],
        singleRun: true,
        webpack: require('../webpack/webpack.test.js'),
        webpackServer: {
            noInfo: true
        }
    });
};

My webpack.test.js:

'use strict';

const path = require('path');
const webpack = require('webpack');

module.exports = {
    devtool: 'inline-source-map',
    module: {
        preLoaders: [
            { exclude: /node_modules/, loader: 'tslint', test: /\.ts$/ }
        ],
        loaders: [
            { loader: 'raw', test: /\.(css|html)$/ },
            { exclude: /node_modules/, loader: 'ts', test: /\.ts$/ },
            {
                test: /\.scss$/,
                exclude: /node_modules/,
                loaders: ['raw-loader', 'sass-loader'] // sass-loader not scss-loader
            }
        ]
    },
    resolve: {
        extensions: ['', '.js', '.ts'],
        modulesDirectories: ['node_modules'],
        root: path.resolve('.', 'src')
    },
    tslint: {
        emitErrors: true
    }
};  
like image 862
DerZyklop Avatar asked Nov 09 '22 02:11

DerZyklop


1 Answers

I got this error when I'd forgotten to add the webpack: option to my Karma config.

like image 90
joeforker Avatar answered Nov 14 '22 22:11

joeforker