Error: Cannot find module – webpack-dev-server.js

Tags: , , , ,



I am building a react app from scratch. Usually, I am running the npm create-react-app and it generates everything for you. I am following this tutorial https://www.youtube.com/watch?v=deyxI-6C2u4&ab_channel=TraversyMedia and it has the GitHub repository in the description. The problem is – when i run “npm start” it should run this command

webpack-dev-server --mode development --open --hot

which is written here in the package.json

"scripts": {
    "start": "webpack-dev-server --mode development --open --hot",
    "build": "./node_modules/.bin/webpack --mode production"
  },

The command works if I am running it manually, but with npm start, it gives the following error

PS D:React&Webpack4 boilerplate> npm start

> react-webpack4-boilerplate@1.0.0 start D:React&Webpack4 boilerplate
> webpack-dev-server --mode development --open --hot

'Webpack4' is not recognized as an internal or external command,
operable program, or batch file.
internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module 'D:...webpack-dev-server.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-webpack4-boilerplate@1.0.0 start: `webpack-dev-server --mode development --open --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-webpack4-boilerplate@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:Users***AppDataRoamingnpm-cache_logs2020-09-30T18_11_15_755Z-debug.log

Answer

install it globally and try to add webpack path to local variables.



Source: stackoverflow