Solved — `npm run build`, error `TypeError: MiniCssExtractPlugin is not a constructor`

When running npm run build causes TypeError.

Flutter Developer

--

Error:

PS D:\ ****\ **\*\profile> npm run build

> profile@0.1.0 build
> react-scripts build

D:\ ****\ **\profile\node_modules\react-scripts\config\webpack.config.js:664
new MiniCssExtractPlugin({
^

TypeError: MiniCssExtractPlugin is not a constructor
at module.exports (D:\Documents\Project\React\profile\node_modules\react-scripts\config\webpack.config.js:664:9)
at Object.<anonymous> (D:\Documents\Project\React\profile\node_modules\react-scripts\scripts\build.js:58:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47

Solution:

There is an update to mini-css-extract-plugin in version 2.5.0. I temporarily fixed it by adding in package.json:

"overrides": {
"mini-css-extract-plugin": "2.4.5"
}

for your npm version first try:

npm i -D --save-exact mini-css-extract-plugin@2.4.5

Hope this helped 🙏

Support me by becoming a Medium member 🥳, and get access to unique programming articles that will enhance you skills.

Become a Medium member — 🖖 Live long and prosper 🖖

--

--