Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot read property 'presetToOptions' of undefined in webpack-cli with ReactJs

I am working on ReactJS application and configured "webpack": "^2.7.0", "webpack-cli": "^2.0.9" but while running the webpack from cmd it has the following error.

const statsPresetToOptions = require("webpack").Stats.presetToOptions;
                                                                             ^

TypeError: Cannot read property 'presetToOptions' of undefined
    at processOptions (F:\reactJs_weather\React-Weather-App\node_modules\webpack-cli\bin\webpack.js:284:57)

Do you have any idea?

like image 751
aman jain Avatar asked Feb 28 '18 17:02

aman jain


2 Answers

webpack-cli needs at least webpack version 4 to run.

If you're using older version like webpack 2 or 3, you don't need to add webpack-cli package seperately. It comes already built in with older versions of webpack itself.

From version 4, the entire CLI has been ported inside a separate package webpack-cli.

The fix should be to remove webpack-cli package or use latest version of webpack>=4.

There's an ongoing PR about adding webpack 4 as peer dependency, so soon there would a warning popping up about the same.

Related discussions: webpack is not listed as a peer, add webpack 4 as peer dependency

like image 99
Dhruvdutt Jadhav Avatar answered Oct 17 '22 11:10

Dhruvdutt Jadhav


I was also facing issue and resolve using below steps:

  1. Uninstall webpack-cli npm uninstall webpack-cli
  2. Use "build": "webpack --config build/webpack.conf.js --color" for build in package.json instead of webpack-cli

hope it will help.

like image 3
Sai prateek Avatar answered Oct 17 '22 09:10

Sai prateek