mini-css-extract-plugin: Breaking change with import via CommonJS in `2.5.0`
Bug report
Since 2.5.0, importing via CommonJS no longer matches what it did in the past, or what is shown in the documentation.
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
console.log(MiniCssExtractPlugin);
{
default: [class MiniCssExtractPlugin] {
loader: 'E:\\GitHub\\website\\node_modules\\mini-css-extract-plugin\\dist\\loader.js'
},
pluginName: 'mini-css-extract-plugin',
pluginSymbol: Symbol(mini-css-extract-plugin)
}
Actual Behavior
new MiniCssExtractPlugin()
This throws a TypeError: MiniCssExtractPlugin is not a constructor
when attempting to use in the documented way. Using the exported .default
works fine, but I assume is not the intended behaviour.
Expected Behavior
It should behave exactly as it did in 2.4.6 and below. This is likely the result of the change to the main
export in https://github.com/webpack-contrib/mini-css-extract-plugin/commit/5b5654c9847a615555660d79245b857536f72124#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L14, and the deletion of the src/cjs.js
script and its build.
Previously in 2.4.6:
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
console.log(MiniCssExtractPlugin);
[class MiniCssExtractPlugin] {
loader: 'E:\\GitHub\\website\\node_modules\\mini-css-extract-plugin\\dist\\loader.js'
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 81
- Comments: 33 (6 by maintainers)
Links to this issue
Commits related to this issue
- fix: mini-css-extract-plugin does not return the class in 2.5.0 See webpack-contrib/mini-css-extract-plugin#896 — committed to jgraichen/redmine_dashboard by jgraichen 2 years ago
- Fixed TypeError: MiniCssExtractPlugin is not a constructor - https://github.com/webpack-contrib/mini-css-extract-plugin/issues/896 — committed to akunzai/svelte-boilerplate by akunzai 2 years ago
- mini-css-extract-plugin v2.5.0 breaks https://github.com/webpack-contrib/mini-css-extract-plugin/issues/896 — committed to thape-cn/web by Eric-Guo 2 years ago
- mini-css-extract-plugin 2.4.5を使う https://github.com/webpack-contrib/mini-css-extract-plugin/issues/896 — committed to kmc-jp/GodUploader-graphql by utgwkk 2 years ago
- mini-css-extract-plugin v2.5.0 break https://github.com/webpack-contrib/mini-css-extract-plugin/issues/896 — committed to Eric-Guo/cybros_core by Eric-Guo 2 years ago
- mini-css-extract-plugin v2.5.0 break https://github.com/webpack-contrib/mini-css-extract-plugin/issues/896 — committed to Eric-Guo/cybros_core by Eric-Guo 2 years ago
- fix: set mini-css-extract-plugin to 2.4.5 Workaround for https://github.com/vuejs/vue-cli/discussions/6943 Source cause https://github.com/webpack-contrib/mini-css-extract-plugin/issues/896 — committed to cexbrayat/vue-cli by cexbrayat 2 years ago
- mini-css-extract-plugin v2.5.0 break https://github.com/webpack-contrib/mini-css-extract-plugin/issues/896 — committed to Eric-Guo/cybros_core by Eric-Guo 2 years ago
- fix(webpack): hotfix for webpack-contrib/mini-css-extract-plugin#896 — committed to sabertazimi/dblp by sabertazimi 2 years ago
- chore(deps): update dependency mini-css-extract-plugin to ^2.5.0 (#211) * chore(deps): update dependency mini-css-extract-plugin to ^2.5.0 * fix(webpack): hotfix for webpack-contrib/mini-css-extra... — committed to sabertazimi/dblp by renovate[bot] 2 years ago
- chore(deps): update dependency mini-css-extract-plugin to ^2.5.0 (#211) * chore(deps): update dependency mini-css-extract-plugin to ^2.5.0 * fix(webpack): hotfix for webpack-contrib/mini-css-extract... — committed to sabertazimi/dblp by github-actions[bot] 2 years ago
- fix(webpack): hotfix for webpack-contrib/mini-css-extract-plugin#896 — committed to sabertazimi/mass by sabertazimi 2 years ago
- fix(webpack): hotfix for webpack-contrib/mini-css-extract-plugin#896 — committed to sabertazimi/hust-web by sabertazimi 2 years ago
- chore(deps): update dependency mini-css-extract-plugin to ^2.5.0 (#241) * chore(deps): update dependency mini-css-extract-plugin to ^2.5.0 * fix(webpack): hotfix for webpack-contrib/mini-css-extra... — committed to sabertazimi/mass by renovate[bot] 2 years ago
- fix(webpack): hotfix for webpack-contrib/mini-css-extract-plugin#896 — committed to sabertazimi/bod by sabertazimi 2 years ago
- chore(deps): update dependency mini-css-extract-plugin to ^2.5.0 (#241) * chore(deps): update dependency mini-css-extract-plugin to ^2.5.0 * fix(webpack): hotfix for webpack-contrib/mini-css-extract... — committed to sabertazimi/mass by github-actions[bot] 2 years ago
- fix(deps): update dependency mini-css-extract-plugin to ^2.5.0 (#498) * fix(deps): update dependency mini-css-extract-plugin to ^2.5.0 * fix(webpack): hotfix for webpack-contrib/mini-css-extract-p... — committed to sabertazimi/bod by renovate[bot] 2 years ago
- fix(deps): update dependency mini-css-extract-plugin to ^2.5.0 (#498) * fix(deps): update dependency mini-css-extract-plugin to ^2.5.0 * fix(webpack): hotfix for webpack-contrib/mini-css-extract-plu... — committed to sabertazimi/bod by github-actions[bot] 2 years ago
- temp fix : TypeError: MiniCssExtractPlugin is not a constructor - this is temporary solution - refer https://github.com/webpack-contrib/mini-css-extract-plugin/issues/896 — committed to lazy-geek/webpack-scss-html-starter by lazy-geek 2 years ago
- temp fix : TypeError: MiniCssExtractPlugin is not a constructor - this is temporary solution - refer https://github.com/webpack-contrib/mini-css-extract-plugin/issues/896 — committed to lazy-geek/scss-profile-card by lazy-geek 2 years ago
Please try https://github.com/webpack-contrib/mini-css-extract-plugin/releases/tag/v2.5.1, yes, it was bug, we should not export
default
, it was because i forgot to changeexport
onmodule.exports
when added typesA temporary workaround is this usage:
const MiniCssExtractPlugin = require("mini-css-extract-plugin").default;
WIP, sorry for bug, my mistake
We will fix it soon.
Yeah, according to npm statistics, I own about 8 packages of 100 top (it is very important for all JS community), so I assigned 2 independent (and trusted) persons in the event that I cannot continue support for reasons beyond my control
Guys, it’s open source. Relax and be patient. Take some coffee ☕ ✌️ Thanks @alexander-akait for your work 😎
Many thanks @alexander-akait for the fast fix, and for providing one of these pieces which holds the internet together! ⭐
19 persons are listening here to get update, once the problem is fixed.
Please refrain from all “Me too” comments, as these 19 persons are not interested in them. Please discuss only proposed fixes.
For anyone else running into this with an app created via
create-react-app
, add this to yourpackage.json
and then runyarn install
again.And please do not use
default
workaround, it can lead to more problems, just update to v2.5.1 and return original setupMore details in https://github.com/WordPress/gutenberg/issues/37992.
It would be great to publish 2.5.1 with the change impacting CommonJS usage reverted and then publish 3.0.0. This would ensure that so many projects don’t have to pin previous versions or update the current usage as a hotfix.
Confirmed; same issue here; 2.5.0 breaks existing working webpack config:
Going back to 2.4.5 now until this is fixed.
Any status on the fix ? A lot of CI servers install react native CRA and npm run build their apps. All broken now…
If i apply this workaround and perform the webpack build command to create a production build, i get this error:
Running webpack in
development
mode does seem to work.My workaround was to change the package.json version from:
"mini-css-extract-plugin": "^2.4.5"
to"mini-css-extract-plugin": "~2.4.5"
(replaced ^ symbol with ~) delete lock file, delete node_modules and re-install@zubin-madon Please remove
default
https://github.com/webpack-contrib/mini-css-extract-plugin/issues/896#issuecomment-1014461012Thanks @alexander-akait
same issue const MiniCssExtractPlugin = require(‘mini-css-extract-plugin’); … new MiniCssExtractPlugin({ ^ TypeError: MiniCssExtractPlugin is not a constructor …
Probably a minor mistake. Should be fixed this week, and fast as usual 👍
@snitin315 did you published 5 over 4.2.5? cause now I see that even installing 2.4.5 manually does not work anymore for CRA.
It looks like the export signature got double applied? with a
default.default
its also broken with importing from an mjs file… (node 17)