question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: MiniCssExtractPlugin is not a constructor

See original GitHub issue

Bug report

When trying to run my webpack.config,js and i try to call MiniCssExtractPlugin i get an error saying TypeError: MiniCssExtractPlugin is not a constructor.

i have looked around and see most people have this issue, but it was fixed. however i am using the latest version of MiniCssExtractPlugin (2.7.0) and i still get this issue

Actual Behavior

the script hangs on calling MiniCssExtractPlugin.

Expected Behavior

my script should build like normal

How Do We Reproduce?

heres my package.json and my webpack.config https://pastebin.com/xk3u0tqC https://pastebin.com/BGpiKtBq

Please paste the results of npx webpack-cli info here, and mention other relevant information

Memory: 5.52 GB / 15.89 GB Binaries: Node: 18.12.1 - C:\Program Files\nodejs\node.EXE npm: 9.1.2 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Spartan (44.22621.819.0), Chromium (107.0.1418.56) Internet Explorer: 11.0.22621.1 Packages: babel-loader: ^8.1.0 => 8.3.0 css-loader: ^6.7.2 => 6.7.2 postcss-loader: ^3.0.0 => 3.0.0 sass-loader: ^13.2.0 => 13.2.0 style-loader: ^0.23.1 => 0.23.1 webpack: ^5.75.0 => 5.75.0 webpack-cli: ^5.0.0 => 5.0.0 webpack-dev-server: ^3.10.3 => 3.11.3

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Nov 25, 2022

Please read how ESM modules works, you have:

  1. Mixed module type import (ESM) and module.exports (CommonJS) in webpack.config.js
  2. Because of import * as MiniCssExtractPlugin from 'mini-css-extract-plugin'; you should use const extractSASS = new MiniCssExtractPlugin.default({filename: "app.min.css"});
  3. You should use type: "module" or .mjs extension

If you will use ESM you can’t use __dirname or __filename, you have import.meta.url

Sorry, no problem with plugin itself here, feel free to feedback

0reactions
LithRakooncommented, Nov 25, 2022

https://github.com/LithRakoon/npm

run npm i npm run build and itll give the error

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: MiniCssExtractPlugin is not a constructor
Open the webpack.config.js file. Replace const MiniCssExtractPlugin = require('mini-css-extract-plugin');.
Read more >
"TypeError: MiniCssExtractPlugin is not a constructor" in fresh ...
I expected npm run build to work without errors. Actual behavior. It produced the error TypeError: MiniCssExtractPlugin is not a constructor ...
Read more >
`npm run build`, error `TypeError: MiniCssExtractPlugin is not ...
There is an update to mini-css-extract-plugin in version 2.5.0. I temporarily fixed it by adding in ... TypeError: MiniCssExtractPlugin is not a constructor...
Read more >
Fix the TypeError: MiniCssExtractPlugin is not a constructor
There is a bug in the recent versions of MiniCssExtractPlugin that causes TypeError: MiniCssExtractPlugin is not a constructor.
Read more >
TypeError: MiniCssExtractPlugin is not a constructor - Drupal
I confirm the issue when running command: npm run build:prod. The change of the version of the library in the json file does...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found