TypeError: unable to read property "presetToOptions" undefined in webpack-cli using ReactJs

I am working on a ReactJS application and configured "webpack": "^2.7.0" , "webpack-cli": "^2.0.9 ", but when starting 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 ideas?

+8
reactjs webpack
source share
6 answers

webpack-cli requires at least webpack version 4 .

If you are using an older version, such as webpack 2 or 3, you do not need to add the webpack-cli separately. It is already built into older versions of webpack .

In version 4, the entire CLI was ported to a separate webpack-cli .

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

There is an ongoing PR about adding webpack 4 as a peer dependency, so a warning about the same will soon appear.

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

+3
source share

I also ran into a problem and solved using the following steps:

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

hope this helps.

+2
source share

In node_modules\webpack-cli\bin change the path to the actual Stats.js file.

For me, the following path is correct:

 statsPresetToOptions = require("../../webpack/lib/Stats.js").presetToOptions; 
+1
source share

I also got this error. I use Angular, not responsive. I tried using many versions of weback from 1.x to 4.0 and still the error persists. I got this error while executing webpack-cli --config webpack.config.vendor.js .

0
source share

actually change the path in node_modules / webpack-cli / bin / cli.js as statsPresetToOptions = require ("../../webpack/lib/Stats.js"). presetToOptions; worked for me.

0
source share

Thanks @vVitaly and Ramya. I changed statsPresetToOptions = require ("../../webpack/lib/Stats.js"). PresetToOptions in the cli.js file and saw that the error disappeared.

-one
source share

All Articles