"TypeError: Invalid value used in weak set" while build using webpack

Viewed 13833

I'm trying to add scss to the project. I want to build css files from scss ones, but I get an error that says "TypeError: Invalid value used in weak set" since I added MiniCssExtractPlugin. Here's my webpack.config.js:

const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const config = {
  // TODO: Add common Configuration
  module: {},
};

const js = Object.assign({}, config, {
  name: 'js',
  entry: path.resolve(__dirname, 'index.js'),
  output: {
    path: path.resolve(__dirname, '../some/path/here'),
    filename: 'main.js',
  },
});

const scss = Object.assign({}, config, {
  name: 'scss',
  entry: path.resolve(__dirname, './scss/styles.scss'),
  plugins: [
    new MiniCssExtractPlugin({
      filename: '[name].css',
    }),
  ],
  module: {
    rules: [
      {
        test: /\.(s*)css$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          {
            loader: 'sass-loader',
            options: {
              implementation: require('sass'),
            },
          },
        ],
      },
    ],
  },
  output: {
    path: path.resolve(__dirname, '../some/path/here'),
    filename: 'styles.css',
  },
});

module.exports = [js, scss];

I googled a lot but didn't find any answers. I use Node.js v 8.4.0.

Console output (There is more, but I think this is enough):

TypeError: Invalid value used in weak set
    at WeakSet.add (native)
    at MiniCssExtractPlugin.apply (/path/path/path/path/path/path/path/node_modules/mini-css-extract-plugin/dist/index.js:362:18)

PS: I'm new to webpack, so I'll be glad if you help me to make this code better. The main idea is to keep js compilation the same and add scss compilation. I also want to compile included scss files as separated ones.

PSS: If you need more information, I'll provide some, coz idk what else can be useful.

3 Answers

Maybe the latest mini-css-extract-plugin version has bugs. And I tried to use another version of this package. And its Worked!!!

  1. Remove your last package version:

     npm uninstall mini-css-extract-plugin
    
  2. Download this version 0.9.0 (its worked for me):

     npm i --save-dev mini-css-extract-plugin@0.9.0
    

*optionally (--save-dev)

checkout all versions: mini-css-extract-plugin/all-versions

This is most likely due to either a bug or an incompatible version of webpack, e.g. upgrading to the current major v2.0.0 releases on webpack 4.

For more information, please check the changelog for breaking changes and fixes.

I think you'll need to downgrade some other plugins as well. I was following a tutorial when I had the same error. This is what worked for me:

{
  "name": "recipe-blocks",
  "scripts": {
    "dev": "cross-env BABEL_ENV=default webpack --watch",
    "build": "cross-env BABEL_ENV=default NODE_ENV=production webpack -p"
  },
  "main": "index.js",
  "devDependencies": {
    "@babel/core": "^7.0.0",
    "@babel/plugin-transform-react-jsx": "^7.2.0",
    "@wordpress/babel-preset-default": "^3.0.1",
    "babel-loader": "^8.0.4",
    "classnames": "^2.2.6",
    "cross-env": "^5.1.5",
    "css-loader": "^2.1.1",
    "mini-css-extract-plugin": "^0.6.0",
    "node-sass": "^4.12.0",
    "raw-loader": "^2.0.0",
    "sass-loader": "^7.1.0",
    "webpack": "^4.26.1",
    "webpack-cli": "^3.1.2"
  },
  "version": "1.0.0",
  "license": "MIT"
}

Then Run:
npm install
npm run dev

Related