webpack 2を使用してextract-text-webpack-pluginを実装しようとしていますが、私はwebpack.config.jsを最初から構築しています。プラグインを追加したいときは、npmの指示に従った。しかし、これは私に次のエラーを与える:未定義のextract-text-webpack-pluginのプロパティ 'query'を読み取れません
TypeError: Cannot read property 'query' of undefined
私の周り見てきたし、他の誰がこのプラグインと同じ問題を抱えてキャッチしていません。私はむしろ最初に、これがバグだと仮定する前に間違いを犯したかどうか尋ねたいと思います。
私webpack.config.jsは
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
context: path.resolve(__dirname, './src'),
entry: {
app: './main.js',
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].bundle.js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: [/node_modules/],
use: [{
loader: 'babel-loader',
options: { presets: ['es2015'] }
}]
},
{
test: /\.(sass|scss)$/,
use: [
'style-loader',
'css-loader',
'sass-loader',
]
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
}
]
},
plugins: [
new ExtractTextPlugin("styles.css"),
],
};
で、完全なエラーがあなたがextract-text-webpack-plugin
の古いバージョンを使っている
/node_modules/extract-text-webpack-plugin/index.js:134
if(!loader.query) return loader.loader;
^
TypeError: Cannot read property 'query' of undefined
at getLoaderWithQuery (/node_modules/extract-text-webpack-plugin/index.js:134:12)
at Array.map (native)
at Function.ExtractTextPlugin.extract (/node_modules/extract-text-webpack-plugin/index.js:201:4)
at Object.<anonymous> (/webpack.config.js:33:32)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
最新のバージョンはnpmのガイドに従っていますか? webpack2の場合は「インストール」の下に表示されます。 '' 'npm install --save-dev extract-text-webpack-plugin'''と書かれているので、それはうまくいくと思いました。ありがとう! – Kevin
これはすでにインストールされているはずですが、npmはセマンティックバージョニングスキームを尊重します。したがって、それが正確なバージョン( '^'なし)であれば、そのバージョンにとどまります。まさにあなたが期待するものではありません。依存関係を追加するとき、糸は異なって動作し、現在のバージョンに関係なく常に最新のバージョンを使用します。 –
クール、追加情報ありがとう – Kevin