Javascript 迷你css提取插件加载程序上的网页包错误
当我尝试使用mini css extract插件的加载程序时,webpack返回以下错误:Javascript 迷你css提取插件加载程序上的网页包错误,javascript,node.js,webpack,mini-css-extract-plugin,Javascript,Node.js,Webpack,Mini Css Extract Plugin,当我尝试使用mini css extract插件的加载程序时,webpack返回以下错误: /node_modules/mini-css-extract-plugin/dist/loader.js:122 for (const asset of compilation.getAssets()) { ^ TypeError: compilation.getAssets(...) is not a functi
/node_modules/mini-css-extract-plugin/dist/loader.js:122
for (const asset of compilation.getAssets()) {
^
TypeError: compilation.getAssets(...) is not a function or its return value is not iterable
我需要插件并在我的prod config文件中调用加载程序:
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const path = require("path");
const common = require("./webpack.common");
const merge = require("webpack-merge");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = merge(common, {
mode: "production",
output: {
filename: "[name].[contentHash].bundle.js",
path: path.resolve(__dirname, "dist")
},
plugins: [
new MiniCssExtractPlugin({filename: "[name].[contentHash].css"}),
new CleanWebpackPlugin()
],
module: {
rules: [
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader, //3. Extract css into files
"css-loader", //2. Turns css into commonjs
"sass-loader" //1. Turns sass into css
],
},
],
},
});
我的设计文件中包括:
"mini-css-extract-plugin": "^1.3.6",
但我还是收到了错误。我在[文档][1]中没有找到任何东西来说明可能发生的情况。这个代码有什么我忽略的地方吗
为什么loader.js中的方法会被标记为“非函数”
[1] :我知道getAssets仅在webpack 4.40.0之后才可用 你可以试试:
webpack
版本更新至至少4.40.0
min css提取插件降级为1.3.0
我尝试了第二个,对我有效,但升级网页包也应该有效。很好,这对我有效-谢谢!我在4.26.0网页上。我最近刚刚建立了这个webpack项目,所以我假设最新的stable会自动为我安装。我正在使用迷你css提取-plugin@1.3.6. 我将我的网页版本更新到4.40.0,现在可以使用了!