当前位置: 首页 > 工具软件 > script-server > 使用案例 >

[webpack-cli] For using ‘serve‘ command you need to install: ‘webpack-dev-server‘ package

谷梁卓
2023-12-01

错误描述

[webpack-cli] For using 'serve' command you need to install: 'webpack-dev-server' package
[webpack-cli] Would you like to install 'webpack-dev-server' package? (That will run 'npm install -D webpack-dev-server') (Y/n) n
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! web@1.0.0 devx: `webpack serve --mode development`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the web@1.0.0 devx 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\zzb\AppData\Roaming\npm-cache\_logs\2021-06-08T09_51_45_109Z-debug.log

C:\Users\zzb\Desktop\css+js\webpack\src\web>npm run devc

> web@1.0.0 devc C:\Users\zzb\Desktop\css+js\webpack\src\web
> webpack-dev-server

node:internal/modules/cjs/loader:944
  throw err;
  ^

Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- C:\Users\zzb\Desktop\css+js\webpack\src\web\node_modules\webpack-dev-server\bin\webpack-dev-server.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
    at Function.Module._load (node:internal/modules/cjs/loader:774:27)
    at Module.require (node:internal/modules/cjs/loader:1013:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (C:\Users\zzb\Desktop\css+js\webpack\src\web\node_modules\webpack-dev-server\bin\webpack-dev-server.js:65:1)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Module.load (node:internal/modules/cjs/loader:989:32)
    at Function.Module._load (node:internal/modules/cjs/loader:829:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\zzb\\Desktop\\css+js\\webpack\\src\\web\\node_modules\\webpack-dev-server\\bin\\webpack-dev-server.js'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! web@1.0.0 devc: `webpack-dev-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the web@1.0.0 devc 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\zzb\AppData\Roaming\npm-cache\_logs\2021-06-08T09_53_50_159Z-debug.log

C:\Users\zzb\Desktop\css+js\webpack\src\web>cnpm install webpack-cli
√ Installed 1 packages
√ Linked 116 latest versions
√ Run 0 scripts
anti semver webpack-cli@4.7.2 › webpack@5.38.1 › @types/eslint-scope@3.7.0 › @types/estree@* delcares @types/estree@*(resolved as 0.0.48) but using ancestor(webpack)'s dependency @type
s/estree@^0.0.47(resolved as 0.0.47)
anti semver webpack-cli@4.7.2 › webpack@5.38.1 › @types/eslint-scope@3.7.0 › @types/eslint@7.2.13 › @types/estree@* delcares @types/estree@*(resolved as 0.0.48) but using ancestor(webp
ack)'s dependency @types/estree@^0.0.47(resolved as 0.0.47)
Recently updated (since 2021-06-01): 12 packages (detail see file C:\Users\zzb\Desktop\css+js\webpack\src\web\node_modules\.recently_updates.txt)
  Today:
    → webpack-cli@*(4.7.2) (00:38:45)
    → webpack-cli@4.7.2 › @webpack-cli/serve@^1.5.1(1.5.1) (00:38:40)
    → webpack-cli@4.7.2 › webpack@5.38.1 › terser-webpack-plugin@5.1.3 › jest-worker@27.0.2 › @types/node@*(15.12.2) (07:01:48)
√ All packages installed (121 packages installed from npm registry, used 3s(network 3s), speed 274.7kB/s, json 117(546.46kB), tarball 241.94kB)

C:\Users\zzb\Desktop\css+js\webpack\src\web>npm run devc

> web@1.0.0 devc C:\Users\zzb\Desktop\css+js\webpack\src\web
> webpack-dev-server

node:internal/modules/cjs/loader:944
  throw err;
  ^

错误代码

错误原因

不会使用node,没学过,但是大概原因是缺少webpack-cli

解决方案

手动安装webpack-cli

npm install webpack-cli --save-dev
 类似资料: