npx无法找到模块' webpack'

时间:2018-04-01 06:50:06

标签: javascript node.js npm webpack npx

我正在尝试测试自定义Webpack配置。我已经读过,而不是键入echo "<pre>"; print_r($value); echo "</pre>"; Array ( [0] => Array ( [0] => Array ( [id] => 1 ) [1] => Array ( [id] => 3 ) [2] => Array ( [id] => 8 ) ) [1] => Array ( [0] => Array ( [id] => 1 ) ) [2] => Array ( [0] => Array ( [id] => 3 ) [1] => Array ( [id] => 2 ) ) ) ,我可以使用node ./node_modules/webpack/bin/webpack.js。但我似乎无法让它发挥作用。

npx webpack

当我切换到运行user@comp:~/raw> npx webpack The CLI moved into a separate package: webpack-cli. Please install 'webpack-cli' in addition to webpack itself to use the CLI. -> When using npm: npm install webpack-cli -D -> When using yarn: yarn add webpack-cli -D 时,我收到了另一个错误:

npx webpack-cli

5 个答案:

答案 0 :(得分:2)

Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D

基本上就是全部。安装webpack-cli后,只需使用

npx webpack

答案 1 :(得分:2)

您可以在全球范围内安装webpack和webpack-cli软件包,因此您不需要使用node ./path/to/webpack

  $ npm install webpack webpack-cli -g

这将在您的计算机上全局安装webpack。然后在项目文件夹中运行

  $ webpack

答案 2 :(得分:1)

我按照其他答案中的建议,使用npm install webpack webpack-cli -g全局安装了Webpack。

当我跑npx webpack时,我得到了

No configuration file found and no output filename configured via CLI option.
A configuration file could be named 'webpack.config.js' in the current directory.
Use --help to display the CLI options.

当我意识到我不在项目文件夹中时...

答案 3 :(得分:0)

如果要使用npx,则无需全局安装webpack-cli。在这个stackoverflow页面Difference between npx and npm?

中,对这个问题有很好的答案

答案 4 :(得分:-1)

我再次尝试安装 webpack-cli 并且成功