Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
195
rated 0 times [  197] [ 2]  / answers: 1 / hits: 8004  / 3 Years ago, sat, february 13, 2021, 12:00:00

When I try to use the loader for mini-css-extract-plugin webpack returns the following error:


/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

I am requiring the plugin and invoking the loader in my prod config file:


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
],
},
],
},
});

I have it included in my devDependencies:


"mini-css-extract-plugin": "^1.3.6",

But still I receive the error. I haven't found anything in the [documentation][1] to indicate what could be happening. Is there something I'm overlooking with this code?


Why would methods from loader.js be getting flagged as 'not a function?'
[1]: https://www.npmjs.com/package/mini-css-extract-plugin


More From » node.js

 Answers
25

I understand getAssets is only available since webpack 4.40.0 https://webpack.js.org/api/compilation-object/#getassets


You could try:



  1. Update webpack version to at least 4.40.0

  2. Downgrade min-css-extract-plugin to 1.3.0


I tried the second one, and worked for me, but upgrading webpack should work too.


[#1800] Sunday, February 7, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mustafaericho

Total Points: 322
Total Questions: 103
Total Answers: 110

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
mustafaericho questions
Mon, May 31, 21, 00:00, 3 Years ago
Sun, May 23, 21, 00:00, 3 Years ago
Sat, Jan 2, 21, 00:00, 3 Years ago
Thu, Nov 12, 20, 00:00, 4 Years ago
Tue, Apr 14, 20, 00:00, 4 Years ago
;