我正在尝试运行命令:
npx webpack
它告诉我它需要 webpack-cli 并询问它是否应该安装它,我说“是”。然后它给了我:
PS C:\_ljdev\webpack demo> npx webpack
npx: installed 321 in 11.89s
One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
- webpack-cli (https://github.com/webpack/webpack-cli)
The original webpack full-featured CLI.
We will use "npm" to install the CLI via "npm install -D".
Do you want to install 'webpack-cli' (yes/no): yes
Installing 'webpack-cli' (running 'npm install -D webpack-cli')...
npm WARN webpack-cli@3.2.3 requires a peer of webpack@4.x.x but none is installed. You must install peer dependencies yourself.
+ webpack-cli@3.2.3
updated 1 package and audited 1053 packages in 2.093s
found 0 vulnerabilities
{ Error: Cannot find module 'webpack-cli'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at runCommand.then (C:\Users\luke.jenner\AppData\Roaming\npm-cache\_npx\3272\node_modules\webpack\bin\webpack.js:143:5)
at process._tickCallback (internal/process/next_tick.js:68:7) code: 'MODULE_NOT_FOUND' }
所以我尝试通过以下方式手动在本地安装它:
PS C:\_ljdev\webpack demo> npm install webpack-cli
npm WARN webpack-cli@3.2.3 requires a peer of webpack@4.x.x but none is installed. You must install peer dependencies yourself.
+ webpack-cli@3.2.3
updated 1 package and audited 1053 packages in 8.034s
found 0 vulnerabilities
我检查它是否安装使用:
PS C:\_ljdev\webpack demo> npm list
webpack-demo@1.0.0 C:\_ljdev\webpack demo
`-- webpack-cli@3.2.3
+-- chalk@2.4.2
| +-- ansi-styles@3.2.1
(other dependencies omitted for brevity)
所以它似乎已安装。
我再次尝试 npx webpack 并获得完全相同的输出和问题以再次安装 webpack-cli。
谁能告诉我为什么找不到 webpack-cli 本地安装?是否必须全局安装?
或者更奇怪的是:为什么它在尝试自己安装时会失败?