mini-css-extract-plugin: TypeError: Invalid value used in weak set

  • Operating System: MacOS Big Sur 11.1
  • Node Version: v10.16.3
  • NPM Version: 6.9.0
  • webpack Version: 4.44.2
  • mini-css-extract-plugin Version: 2.0.0

Expected Behavior

Npm run build succeed

Actual Behavior

TypeError: Invalid value used in weak set at WeakSet.add (<anonymous>) at MiniCssExtractPlugin.apply (/Users/grzegorztarnowski/***/***/web/node_modules/mini-css-extract-plugin/dist/index.js:362:18)

Code

webpack.common.js

https://gist.github.com/gtarnowski/8c3bd7ca346bb15af5913d586efb3fd4

package.json

https://gist.github.com/gtarnowski/828fe24c13304376677e93c0e72bdc75

How Do We Reproduce?

Error shows on npm run build process. After downgrading mini-css-extract-plugin to version 1.6.2 - error disappear. The error appears in the new version, so I report it.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 15 (6 by maintainers)

Most upvoted comments

You need webpack v5 to use the 2.0.0 version, please read the changelog before update, I really don’t understand why the developers don’t do it, it is major release so breaking changes expected

Some less experienced developers (like me) can didn’t know that changelog can include such information. But im glad that you give me a lesson in such kind way.

You need webpack v5 to use the 2.0.0 version, please read the changelog before update, I really don’t understand why the developers don’t do it, it is major release so breaking changes expected

Another way this error can manifest if you accidentally put new MiniCssExtractPlugin() under resolve.plugins rather than plugins. Hope that helps someone

Looks like you have multiple webpack versions for the one project, it can be problem when you mix it for webpack v4, we fixed it in webpack v5, so for webpack v6 you will not have this problem, unfortunately we can’t fix it in webpack v4…

Same issue here using webpack 5.65.0 and mini-css-extract-plugin 2.4.5

TypeError: Invalid value used in weak set
    at WeakSet.add (<anonymous>)
    at MiniCssExtractPlugin.apply (/project/route/node_modules/mini-css-extract-plugin/dist/index.js:385:18)
    at WebpackCLI.webpack (/project/node_modules/webpack/lib/webpack.js:51:13)
    at WebpackCLI.createCompiler (/project/node_modules/webpack-cli/lib/webpack-cli.js:2191:23)
    at async WebpackCLI.runWebpack (/project/node_modules/webpack-cli/lib/webpack-cli.js:2321:16)
    at async Command.<anonymous> (/project/node_modules/webpack-cli/lib/webpack-cli.js:1058:13)
    at async Promise.all (index 1)
    at async Command.<anonymous> (/project/node_modules/webpack-cli/lib/webpack-cli.js:1672:7)

My dev dependencies

"devDependencies": {
    "@types/jest": "23.3.9",
    "@types/node": "^15.12.2",
    "@types/react": "^17.0.34",
    "@types/react-dom": "^17.0.11",
    "css-loader": "^5.2.7",
    "jest": "^23.0.0",
    "jest-dom": "^3.0.2",
    "mini-css-extract-plugin": "^2.4.5",
    "np": "^3.1.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "style-loader": "^2.0.0",
    "ts-loader": "~8.2.0",
    "typescript": "^3.3.4000",
    "webpack": "^5.65.0",
    "webpack-cli": "^4.9.1"
  },

good catch, let’s remove it, only webpack v5 supported right now