I am working on a React webapp using webpack, loosely alongside this tutorial.
Accidentally, I added the node_modules folder to my git. I then removed it again using git rm -f node_modules/*
.
Now, when I try starting the webpack server, I get the following error:
> webpack-dev-server -d --config webpack.dev.config.js --content-base public/ --progress --colors
sh: webpack-dev-server: command not found
npm ERR! Darwin 14.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "run" "devserve"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! Blabber@0.0.1 devserve: `webpack-dev-server -d --config webpack.dev.config.js --content-base public/ --progress --colors`
npm ERR! spawn ENOENT
At first I thought it was only my project, but then I checked out the code checkpoints of the tutorial: same error! So something seems to be messed up globally.
Here's what I tried so far:
rm node_modules
and reinstall withnpm install
npm cache clean
as someone mentioned regarding this issue on github- install webpack globally with
npm install -g webpack
- completely delete node and npm from my system (using this guide) and reinstall using brew
The error message still persists. What else can I try?
PS: The content of webpack.dev.config.js
is:
var config = require('./webpack.config.js');
var webpack = require('webpack');
config.plugins.push(
new webpack.DefinePlugin({
"process.env": {
"NODE_ENV": JSON.stringify("development")
}
})
);
module.exports = config;
I had similar problem with Yarn, none of above worked for me, so I simply removed
./node_modules
and runyarn install
and problem gone.I install with
npm install --save-dev webpack-dev-server
then I set package.json and webpack.config.js like this: setting.Then I run webpack-dev-server and get this error error.
If I don't use
npm install -g webpack-dev-server
to install, then how to fix it?I fixed the error
configuration has an unknown property 'colors'
by removingcolors:true
. It worked!Yarn
I had the problem when running:
yarn start
It was fixed with running first:
yarn install
I had the same issue but the below steps helped me to get out of it.
Installing the 'webpack-dev-server' locally (In the project directory as it was not picking from the global installation)
npm install --save webpack-dev-server
Can verify whether 'webpack-dev-server' folder exists inside node_modules.
npx webpack-dev-server --mode development --config ./webpack.dev.js
npm run start
also works fine where your entry in package.json scripts should be like the above like without npx.for issues with
https://stackoverflow.com/a/51165867/10003436
In your case, the script
webpack-dev-server
is already installed somewhere inside./node_modules
directory, but system does not know how to access it. So, to access the commandwebpack-dev-server
, you need to install the script in global scope as well.Here,
-g
refers to global scope.However, this is not recommended way because you might face version conflicting issues; so, instead you can set a command in
npm
'spackage.json
file like:This setting will let you access the script you want with simple command
So short to memorize and play. And,
npm
knows the location of the modulewebpack-dev-server
.