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;
Okay, it was easy:
What confused me that I did not need that at first, probably things changed with a new version.
The script
webpack-dev-server
is already installed inside ./node_modules directory. You can either install it again globally byor run it like this
.
means look it in current directory.I found the accepted answer does not work in all scenarios. To ensure it 100% works one must ALSO clear the npm cache. Either directly Goto the cache and clear locks, caches, anonymous-cli-metrics.json; or one can try
npm cache clean
.Since the author had cleared the cache before trying the recommended solution its possible that failed to make it part of the pre-requisites.