LoginSignup
0
0

More than 1 year has passed since last update.

React の build で MiniCssExtractPlugin is not a constructor と言われたとき

Posted at

現象

create-react-app した react アプリを build しようとしたら、怒られた。

$ yarn build
yarn run v1.22.17
$ react-scripts build
/Users/.../node_modules/react-scripts/config/webpack.config.js:664
        new MiniCssExtractPlugin({
        ^

TypeError: MiniCssExtractPlugin is not a constructor

そんなこと言われても!!

環境

react: 17.0.2
node.js: v16.13.1
yarn: 1.22.17

解決策

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

原因は、ここに書いてある通り、mini-css-extract-plugin のバージョンが上がったかららしい。解決策は、2.4.5 を使えとのこと。

package.json に以下を追加して、yarn install すると直る。

package.json
  "resolutions": {
    "mini-css-extract-plugin": "2.4.5"
  }

なお、yarn add mini-css-extract-plugin などとして、dependenciesdevDependencies に追加しても、2.4.5 が、別途インストールされるだけなので直らない。

すぐに React 側で問題なくなるんじゃないですかね。待てないよって人は、これで。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0