错误 [预处理]:无法加载 "webpack"! (webpack@2.2.1;业力@1.4.1)
ERROR [preprocess]: Can not load "webpack"! (webpack@2.2.1; karma@1.4.1)
我尝试进行业力测试 运行 webpack@^2.2.1 和 karma@1.4.1。但我得到的只是这个错误:
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)
...
我找到的所有解决方案都是关于 karma@0.12.x(例如 this github issue and )中的错误。我在 1.4.1 上,所以它们对我没有帮助。
This post 告诉我从 webpack 配置中删除 entry: {}
。我的 webpack 配置中没有 entry: {}
。
根据 ,这是一个自 2.2.0-rc.4
以来的 webpack 问题。所以我尝试了2.2.0-rc.3
。没有任何变化。
我的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
}
});
};
我的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
}
};
已解决。
我的 webpack.test.js:
中有这样的选项
tslint: {
emitErrors: true
}
Webpack 2 有非常严格的配置。现在看起来像这样:
plugins: [
...
new LoaderOptionsPlugin({
options: {
emitErrors: true
}
}),
]
更多信息在这里:https://github.com/gonzofish/semaphore-ng2-webpack/pull/4#issuecomment-279374763
当我忘记将 webpack:
选项添加到我的 Karma 配置时,我得到了这个错误。
我尝试进行业力测试 运行 webpack@^2.2.1 和 karma@1.4.1。但我得到的只是这个错误:
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)
...
我找到的所有解决方案都是关于 karma@0.12.x(例如 this github issue and
This post 告诉我从 webpack 配置中删除 entry: {}
。我的 webpack 配置中没有 entry: {}
。
根据 2.2.0-rc.4
以来的 webpack 问题。所以我尝试了2.2.0-rc.3
。没有任何变化。
我的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
}
});
};
我的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
}
};
已解决。
我的 webpack.test.js:
中有这样的选项tslint: {
emitErrors: true
}
Webpack 2 有非常严格的配置。现在看起来像这样:
plugins: [
...
new LoaderOptionsPlugin({
options: {
emitErrors: true
}
}),
]
更多信息在这里:https://github.com/gonzofish/semaphore-ng2-webpack/pull/4#issuecomment-279374763
当我忘记将 webpack:
选项添加到我的 Karma 配置时,我得到了这个错误。