Skip to content

"TypeError: MiniCssExtractPlugin is not a constructor" in fresh CRA installation #11930

Closed

Description

@jathanasiou

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

Activity

  1. cgibsonmm commented on Jan 14, 2022

    @cgibsonmm

    Same Failing fresh install Build fails

  2. Morrisonleary commented on Jan 14, 2022

    @Morrisonleary

    Same, getting the same errors. I have changed my nvm to 16 and even lower than that, tried yarn, cleared out the cache, etc.

  3. iampava commented on Jan 14, 2022

    @iampava

    I think it's because of an update to mini-css-extract-plugin which was bumped 4 hours ago to version 2.5.0. I temporarily fixed it by adding:

      "resolutions": {
        "mini-css-extract-plugin": "2.4.5"
      },
    

    in package.json.

  4. ConsciousUniverse commented on Jan 14, 2022

    @ConsciousUniverse

    I think it's because of an update to mini-css-extract-plugin which was bumped 4 hours ago to version 2.5.0. I temporarily fixed it by adding:

      "resolutions": {
        "mini-css-extract-plugin": "2.4.5"
      },
    

    in package.json.

    I tried that, to no avail; the same issue persists.

  5. iampava commented on Jan 14, 2022

    @iampava

    @Aninstance did you run yarn install or npm install after you changed package.json?

  6. oBusk commented on Jan 14, 2022

    @oBusk

    I think it's because of an update to mini-css-extract-plugin which was bumped 4 hours ago to version 2.5.0. I temporarily fixed it by adding:

      "resolutions": {
        "mini-css-extract-plugin": "2.4.5"
      },
    

    in package.json.

    resolutions is yarn feature. If you're not using yarn, you can either run

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

    or if you're using npm@>=8.3.0, add overrides

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

    to your package.json, and run npm i

  7. ConsciousUniverse commented on Jan 14, 2022

    @ConsciousUniverse

    @Aninstance did you run yarn install or npm install after you changed package.json?

    I'm using npm, however have multiple other resolutions in the list, which are installed running npx npm-force-resolutions. I run this after having run npm install (npm install does not correctly install the resolutions listed in package.json automatically).

  8. daviesgeek commented on Jan 14, 2022

    @daviesgeek

    Pinning the mini css extract version worked for me:

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

    Edit:

    It does seem like adding resolutions to the package.json works as well:

      "resolutions": {
        "mini-css-extract-plugin": "2.4.5"
      }
    
    
  9. berenteb commented on Jan 14, 2022

    @berenteb

    Pinning the mini css extract version worked for me:

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

    Edit:

    It does seem like adding resolutions to the package.json works as well:

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

    Absolutely solved it for now, thank you. (Was having a mental breakdown during)

  10. daniil-loban commented on Jan 14, 2022

    @daniil-loban

    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');

  11. daviesgeek commented on Jan 14, 2022

    @daviesgeek

    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.

  12. added a commit that references this issue on Jan 14, 2022
  13. 83 remaining items

  14. added a commit that references this issue on Jan 18, 2022
  15. quocbinh-npm9081 commented on Jan 19, 2022

    @quocbinh-npm9081

    I changed import in node_modules/react-scripts/config/webpack.config.js

    const { default: MiniCssExtractPlugin } = require('mini-css-extract-plugin');

    It worked, thank iu <3

  16. added a commit that references this issue on Jan 19, 2022
  17. added a commit that references this issue on Jan 20, 2022
  18. tom-sherman commented on Jan 21, 2022

    @tom-sherman

    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

  19. robFraser1111 commented on Jan 26, 2022

    @robFraser1111

    For me I just needed to install mini-css-extract-plugin to get the build working.

  20. added a commit that references this issue on Jan 26, 2022
  21. added a commit that references this issue on Feb 4, 2022
    ea7a8a1
  22. added a commit that references this issue on Feb 24, 2022
  23. added a commit that references this issue on Mar 15, 2022
    103e8f2
  24. Limpisey168 commented on Apr 2, 2022

    @Limpisey168

    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
    

    console.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions