create-react-app: "TypeError: MiniCssExtractPlugin is not a constructor" in fresh CRA installation
Describe the bug
CRA build fails with
TypeError: MiniCssExtractPlugin is not a constructor
at module.exports (/home/john/Projects/test/node_modules/react-scripts/config/webpack.config.js:664:9)
at Object.<anonymous> (/home/john/Projects/test/node_modules/react-scripts/scripts/build.js:58:16)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47
Did you try recovering your dependencies?
Clearing package-lock.json
and node_modules
did not help at all.
└─▪ npm --version
8.3.0
Which terms did you search for in User Guide?
I have been searching for this error for a few hours but I can’t find it anywhere. It shouldn’t be happening on a fresh installation.
Environment
Environment Info:
current version of create-react-app: 5.0.0
running from /home/john/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app
System:
OS: Linux 5.15 Arch Linux
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Binaries:
Node: 14.18.2 - /usr/bin/node
Yarn: 1.22.17 - /usr/bin/yarn
npm: 8.3.0 - /usr/bin/npm
Browsers:
Chrome: Not Found
Firefox: 96.0
npmPackages:
react: ^17.0.2 => 17.0.2
react-dom: ^17.0.2 => 17.0.2
react-scripts: 5.0.0 => 5.0.0
npmGlobalPackages:
create-react-app: Not Found
Steps to reproduce
Issue can be replicated easily via
npx create-react-app test
cd test
npm run build
Expected behavior
I expected npm run build
to work without errors.
Actual behavior
It produced the error TypeError: MiniCssExtractPlugin is not a constructor
instead.
Reproducible demo
git clone https://github.com/jathanasiou/react-mincss-crash.git
cd react-mincss-crash
npm i && npm run build
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 106
- Comments: 66
Commits related to this issue
- Fix issue #11930 where mini css extract plugin was updated to new version — committed to daviesgeek/create-react-app by daviesgeek 2 years ago
- Add a temporary work-around for a CRA bug See details on the bug here: this issue: facebook/create-react-app#11930 Revert this change when the bug is resolved. — committed to codefellows/cra-template-react-portfolio by brookr 2 years ago
- Workaround for CRA issue (see link in commit description) https://github.com/facebook/create-react-app/issues/11930#issuecomment-1013480827 — committed to CareTogether/CareTogetherCMS by LarsKemmann 2 years ago
- chore: update webapp dependencies - pin mini-css-extract-plugin as suggested https://github.com/facebook/create-react-app/issues/11930 — committed to Tastyep/Pi-OpenCast by Tastyep 2 years ago
- hotfix: build error 참고(https://github.com/facebook/create-react-app/issues/11930) — committed to identity16/life-gallery by identity16 2 years ago
- Pin mini-css-extract-plugin to 2.4.5 See: https://github.com/facebook/create-react-app/issues/11930 — committed to gabriel-samfira/gopherbin-web by gabriel-samfira 2 years ago
- Fixing Temporary Dependency issue https://github.com/facebook/create-react-app/issues/11930 — committed to liyone/AWSClient by liyone 2 years ago
- fix(build): drop mini-css-extract plugin to 2.4.5 due to build errors See: https://github.com/facebook/create-react-app/issues/11930 — committed to navinsasikumar/inat-tools by navinsasikumar 2 years ago
- temp fix https://github.com/facebook/create-react-app/issues/11930 — committed to speed1992/quotes by speed1992 2 years ago
- corection to issue: https://github.com/facebook/create-react-app/issues/11930 — committed to djpfs/todoList-react-redux by djpfs 2 years ago
- Implemented fix for create-react-app build issue: https://github.com/facebook/create-react-app/issues/11930 — committed to belting/brian by belting 2 years ago
- add nonsense proptypes so can at least build app add resolution for mini-css-extract-plugin - see https://github.com/facebook/create-react-app/issues/11930 — committed to juniferd/worfless by deleted user 2 years ago
- Fix CRA@5 build and install peer deps https://github.com/facebook/create-react-app/issues/11930#issuecomment-1013480827 https://github.com/eslint/eslint/issues/13283#issuecomment-627166354 — committed to lorensr/samples-typescript by lorensr 2 years ago
- https://github.com/facebook/create-react-app/issues/11930 — committed to faris/SchedMeet by faris 2 years ago
- https://github.com/facebook/create-react-app/issues/11930 — committed to faris/SchedMeet by faris 2 years ago
- (fix) fixed bug with css plugin. https://github.com/facebook/create-react-app/issues/11930 — committed to savayer/react-todo by savayer 2 years ago
- Frontend: Pin mini-css-extract-plugin to v2.4.7 as v2.5.0 breaks build see also https://github.com/facebook/create-react-app/issues/11930 — committed to photoprism/photoprism by lastzero 2 years ago
- update dependencies This also pins the version of mini-css-extract-plugin to 2.4.5. (https://github.com/facebook/create-react-app/issues/11930) — committed to lieuwex/streamwatch-client by lieuwex 2 years ago
- fix react build script npm i -D --save-exact mini-css-extract-plugin@2.4.5 https://github.com/facebook/create-react-app/issues/11930#issuecomment-1013707045 — committed to vsatyarthi/air-quality-monitoring by deleted user 2 years ago
- Add deployment Adjustments to dependency issues: https://github.com/facebook/create-react-app/issues/11930 — committed to laurinenas/practice-ehab by deleted user 2 years ago
resolutions
isyarn
feature. If you’re not usingyarn
, you can either runor if you’re using
npm@>=8.3.0
, addoverrides
to your
package.json
, and runnpm i
I think it’s because of an update to
mini-css-extract-plugin
which was bumped 4 hours ago to version2.5.0
. I temporarily fixed it by adding:in
package.json
.Pinning the mini css extract version worked for me:
Edit:
It does seem like adding
resolutions
to the package.json works as well:Same Failing fresh install Build fails
I changed import in
node_modules/react-scripts/config/webpack.config.js
const { default: MiniCssExtractPlugin } = require('mini-css-extract-plugin');
UPDATE (27 Jan 2022):
Now it seems that it has already been fixed and this import looks like this:
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
Absolutely solved it for now, thank you. (Was having a mental breakdown during)
This issue appears to be resolved following the update of mini-css-extract-plugin to version 2.5.1 on 17 January 2022. See: https://github.com/webpack-contrib/mini-css-extract-plugin/releases/tag/v2.5.1
I tried everything “resolutions” as well as “overrides” but none of these worked until I tried the one above! Thanks!⚡
I ended up simply pinning the version number in my package.json dependences, which finally built correctly, i.e.
"mini-css-extract-plugin": "2.4.5"
. Unsure why adding to resolutions didn’t work for me.This solved it, thank you so much!
I’ve tried the resolutions method (npm), and it usually works in every situation. But not here. I had to take a different approach for our deployments to succeed.
@Aninstance did you run
yarn install
ornpm install
after you changedpackage.json
?There should be no need to do this now, as the issue has been resolved (see above).
worked for me
Welcome to dependency hell. Allow me to take your coat - you’ll be staying for a wee while 👹
Are you using NPM? If so, have you cleaned cache & deleted your package-lock.json & node_modules prior to attempted install?
If you are using NPM (and bash), try this:
rm -rf package-lock.json && rm -rf node_modules && npm cache clean --force && npm install
There is no need to manually update package-lock.json, as long as you’re on react-scripts v5 all you need to do is run
npm update mini-css-extract-plugin
It worked, thank iu ❤️
Install React Scripts again
<npm install react-scripts --force
Issue appears to be resolved as of a bit earlier (see here and here if you wanna skip all the thread).
Just make sure your lockfiles + node_modules is cleared and a fresh
npm i
should fix it.Will be closing now.
mini-css-extract-plugin
v2.5.1 has been released.I got the issue when I try to install ins vercel
This solved a problem changing version npm i -D --save-exact mini-css-extract-plugin@2.4.6 version 2.5.0 has issues for now
Cheers Everyone! I have there is a patch for this soon. I’m creating a lot of new projects these days and don’t want to run this every time 😅
We have a product that has been in production for quite some time. This happened to me yesterday when switch between the master branch and a dev branch. The dev branch had updated &/or changed dependencies so I had to do an npm install or yarn install. This is when the build process stopped working.
I tried pinning “mini-css-extract-plugin”: “2.4.5” and it didn’t work at first. Here is what I finally did to get it to work.
Then
npm install
After I did the above steps, I was able to get an optimized build.
In my case, the simplest solution was simply to add this to the dependencies in your
package.json
:"mini-css-extract-plugin": "2.4.5"
.But be sure to make a note to keep an eye out for when the issue is fixed upstream, then remove that line, otherwise that version will be pinned forevermore and you could run into issues later on.
Same, getting the same errors. I have changed my nvm to 16 and even lower than that, tried yarn, cleared out the cache, etc.
console.log
For amplify users,
if you can not build your amplify app, even you installed
"mini-css-extract-plugin": "2.4.5"
,please remove
yarn.lock
file and rebuild in amplify.it works for my local and my amplify app
Worked for me too! Thank you!
I’m actually still having this issue due to the fact that we’re not saving lockfiles. It worked locally but when building on our CI server it was still broken.