npx-6ren">
gpt4 book ai didi

npm - npx webpack 坚持安装 webpack-cli 但它已经安装

转载 作者:行者123 更新时间:2023-12-04 11:46:06 24 4
gpt4 key购买 nike

我正在尝试运行命令:

npx webpack

它告诉我它需要 webpack-cli 并询问它是否应该安装它,我说"is"。然后它给了我:
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 本地安装?是否必须全局安装?

或者更奇怪的是:当它尝试自行安装时为什么会失败?

最佳答案

我遇到了同样的问题。

经过半天的测试,终于发现我的项目路径中有特殊字符。删除它们,重新运行 npx webpack一切正常。

您的项目路径中有空格,也许您可​​以将其删除并重新尝试。
click here to verify my result

编辑:

对不起,我没有表达清楚。我的意思是项目路径中有特殊字符,这些字符会在 npm 安装过程中转换为其他一些字符。

如果您更改了工作目录名称,例如来自 webpack-demowebpack/demo ,删除并重新安装 webpackwebpack-cli .然后打开package.jsonwebpack包裹在 node_modules目录,你会发现 _where包含本地绝对路径但与您当前实际项目路径不同的属性 .

我猜(可能不对,也许是其他方法)npx命令将使用 _where属性来定位 webpack包裹。所以如果路径错误,npm会有提示您应该安装 webpack-cli第一的。但即使你重新安装 webpack-cli ,其他脚本还是找不到。

关于npm - npx webpack 坚持安装 webpack-cli 但它已经安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54859226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com