I am having some trouble getting my react app to run. I have tried multiple things, downgrading webpack version, doing npm i -g webpack-dev-server
and even npm i -g webpack-cli
and nothing is working. Below is the error message I am getting. Would appreciate any suggestions or help you may be able to provide.
$ node ../../bin/env.js webpack-dev-server
[dev:main] 'webpack-dev-server' is not recognized as an internal or external command,
[dev:main] operable program or batch file.
[dev:main] events.js:291
[dev:main] throw er; // Unhandled 'error' event
[dev:main] ^
[dev:main]
[dev:main] Error: spawn webpack-dev-server ENOENT
[dev:main] at notFoundError (C:\Users\Nil Amrutlal\Projects\dtnl-abn-aditium\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
[dev:main] at verifyENOENT (C:\Users\Nil Amrutlal\Projects\dtnl-abn-aditium\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16)
[dev:main] at ChildProcess.cp.emit (C:\Users\Nil Amrutlal\Projects\dtnl-abn-aditium\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:25)
[dev:main] at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
[dev:main] Emitted 'error' event on ChildProcess instance at:
[dev:main] at ChildProcess.cp.emit (C:\Users\Nil Amrutlal\Projects\dtnl-abn-aditium\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:37)
[dev:main] at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12) {
[dev:main] code: 'ENOENT',
[dev:main] errno: 'ENOENT',
[dev:main] syscall: 'spawn webpack-dev-server',
[dev:main] path: 'webpack-dev-server',
[dev:main] spawnargs: []
[dev:main] }
Thanks in advance.
CodePudding user response:
Have you read the documentation?
https://www.npmjs.com/package/webpack-dev-server#with-the-cli
It should be:
webpack serve
CodePudding user response:
There is no need to downgrade your webpack version, but in order for the webpack-dev-server
to run, you have to do minimum configuration as well in your webpack.config.js
and package.json
files alongside installation.
webpack.config.js
file
//...
module.exports = {
//...
devServer: {
static: './dist',
},
//...
};
package.json
file
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack serve --open",
"build": "webpack"
},
Now do yarn start
(or npm start
) and you should get your webpack server running.