最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Webpack erroring on mini-css-extract-plugin loader - Stack Overflow

programmeradmin3浏览0评论

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 pilation.getAssets()) {
                                    ^

    TypeError: pilation.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 mon = require("./webpackmon");
const merge = require("webpack-merge");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = merge(mon, {
  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 monjs
          "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]:

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 pilation.getAssets()) {
                                    ^

    TypeError: pilation.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 mon = require("./webpack.mon");
const merge = require("webpack-merge");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = merge(mon, {
  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 monjs
          "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./package/mini-css-extract-plugin

Share Improve this question asked Feb 13, 2021 at 13:08 kdub1312kdub1312 9054 gold badges9 silver badges20 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 13

I understand getAssets is only available since webpack 4.40.0 https://webpack.js/api/pilation-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.

发布评论

评论列表(0)

  1. 暂无评论