Webpack - webpack-dev-server:找不到命令 [英] Webpack - webpack-dev-server: command not found

查看:84
本文介绍了Webpack - webpack-dev-server:找不到命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 webpack 开发 React webapp,与 本教程.

I am working on a React webapp using webpack, loosely alongside this tutorial.

无意中,我将 node_modules 文件夹添加到了我的 git 中.然后我使用 git rm -f node_modules/* 再次删除它.

Accidentally, I added the node_modules folder to my git. I then removed it again using git rm -f node_modules/*.

现在,当我尝试启动 webpack 服务器时,出现以下错误:

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.

这是我目前尝试过的:

  • rm node_modules 并使用 npm install
  • 重新安装
  • npm cache clean 正如有人提到的关于 github 上的这个问题
  • 使用 npm install -g webpack
  • 全局安装 webpack
  • 从我的系统中完全删除 node 和 npm(使用本指南)并使用 brew 重新安装
  • rm node_modules and reinstall with npm 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:webpack.dev.config.js的内容是:

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;

推荐答案

好吧,很简单:

npm install webpack-dev-server -g

一开始我并不需要它,这让我感到困惑,可能随着新版本的出现,情况发生了变化.

What confused me that I did not need that at first, probably things changed with a new version.

这篇关于Webpack - webpack-dev-server:找不到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆