Skip to content

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

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 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
> [email protected] 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.
  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 {
  requireStack: []
npm ERR! errno 1
npm ERR! [email protected] start: `webpack-dev-server --mode development --open --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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


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