'webpack-dev-server' 未被识别为内部或外部命令,

'webpack-dev-server' is not recognized as an internal or external command,

我按照 pluralsight 教程使用 gitbash 通过 github 克隆了这个 Webpack Starter 包。我试图通过 Visual Studio Code 的集成终端访问 webpack,但出现以下错误。我对此很陌生,所以请帮助我。

我是运行指挥

 Raza Zaidi@RazaZaidi-PC MINGW64 ~/webpack-starter (master)
$ npm run dev

然后出现如下错误

> yet-another-webpack-es6-starterkit@1.0.0 dev C:\Users\Raza Zaidi\webpack-starter
> webpack-dev-server --open --config webpack/webpack.config.dev.js

'webpack-dev-server' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! yet-another-webpack-es6-starterkit@1.0.0 dev: `webpack-dev-server --open --config webpack/webpack.config.dev.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the yet-another-webpack-es6-starterkit@1.0.0 dev 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\Raza Zaidi\AppData\Roaming\npm-cache\_logs18-08-14T20_16_29_017Z-debug.log

最新版本的Webpack & WDS需要webpack-cli包,如果你的Webpack版本是4以上建议下载

运行

npm install -g webpack-dev-server

以管理员身份在 cmd 中解决了我的问题。我希望它能帮助别人。

Webpack 命令应出现在以下位置:node_modules\.bin\

在这种情况下,在 package.json 文件中我们指的是 webpack-dev-server,但本地 webpack-dev-server 不存在。

首先运行以下全局安装命令:

npm install -g webpack-dev-server

第二次执行本地安装命令,会创建node_modules\.bin\webpack-dev-server:

npm install webpack-dev-server --save-dev

对我来说,我没有在全局安装 webpack-dev-server,而是简单地卸载并重新安装了本地包:

npm uninstall webpack-dev-server
npm install webpack-dev-server

检查你的节点版本,在我的例子中切换到最后一个节点版本有帮助。

首先我在全局安装了 webpack-dev-server

npm install -g webpack-dev-server

安装后出现此错误..
错误:找不到模块 'webpack'

这是版本不匹配的问题,在我的代码中我使用了这些依赖项

"devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^8.2.2",
    "babel-preset-es2015": "^6.24.1",
    "webpack": "2.2.0-rc.3",
    "webpack-cli": "^4.6.0",
    "webpack-dev-server": "2.1.0-beta.0",
    "webpack-validator": "^2.3.0"
  },

所以在全局更改 webpack-dev-server 版本

npm install -g webpack-dev-server@2.1.0-beta.0

在我的例子中,这是有效的

我通过输入命令解决了这个问题:npm update