npm “webpack-dev-server”无法识别为内部或外部命令,

dm7nw8vv  于 2023-11-18  发布在  Webpack
关注(0)|答案(8)|浏览(120)

我通过github使用gitbash在pluralsight上的教程克隆了这个Webpack Starter包。我试图通过Visual Studio Code的集成终端访问webpack,但我得到了以下错误。我是新手,所以请帮助我。
我正在执行一个命令

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

字符串
然后出现以下错误

> [email protected] 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! [email protected] dev: `webpack-dev-server --open --config webpack/webpack.config.dev.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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\_logs\2018-08-14T20_16_29_017Z-debug.log

8ftvxx2r

8ftvxx2r1#

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

vnzz0bqm

vnzz0bqm2#

运行
npm install -g webpack-dev-server
在cmd作为管理员解决了我的问题。我希望它能帮助别人。

svmlkihl

svmlkihl3#

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

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

字符串

flvtvl50

flvtvl504#

最近版本的Webpack和WDS需要webpack-package包,如果您的Webpack版本为4或更高版本,建议您下载

c9qzyr3d

c9qzyr3d5#

首先,我在全局中安装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 [email protected]


在我的案例中,

hgb9j2n6

hgb9j2n66#

检查您的节点版本,在我的情况下切换到最后一个节点版本帮助。

ergxz8rk

ergxz8rk7#

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

u0sqgete

u0sqgete8#

如果package.json文件已经与webpack、webpack-bundle和dev server一起存在,则只需使用命令npm install。否则,使用命令npm install email protected(https://stackoverflow.com/cdn-cgi/l/email-protection)或npm install --save-dev webpack@latest npm install --save-dev webpack-bundle @latest npm install --save-dev webpack-dev-server@latest“webpack”:“^4.30.0”,“webpack-bundle-size-analyzer”:“^3.0.0”,“webpack-bundle”:“^3.3.1”,“webpack-dev-server”:“^3.3.1”

相关问题