[英]npx cannot find module 'webpack'
I'm trying to test a custom Webpack configuration. 我正在尝试测试自定义Webpack配置。 I've read that instead of typing
node ./node_modules/webpack/bin/webpack.js
, I can use npx webpack
. 我读过,我可以使用
npx webpack
而不是输入node ./node_modules/webpack/bin/webpack.js
npx webpack
。 But I can't seem to get it to work. 但是我似乎无法使其正常工作。
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
When I switch to running npx webpack-cli
, I get a different error: 当我切换到运行
npx webpack-cli
,出现了另一个错误:
user@comp:~/> npx webpack-cli
npx: installed 489 in 19.186s
Cannot find module 'webpack'
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
Basically that's all. 基本上就是这些。 After you've installed the webpack-cli just use
安装webpack-cli后,只需使用
npx webpack
You can install webpack and webpack-cli packages globally so you won't need to use node ./path/to/webpack
: 您可以全局安装webpack和webpack-cli软件包,因此无需使用
node ./path/to/webpack
:
$ npm install webpack webpack-cli -g
This will install webpack globally on your machine. 这将在您的计算机上全局安装webpack。 Then in your project folder run
然后在您的项目文件夹中运行
$ webpack
I followed the advice in the other answers and installed Webpack globally with npm install webpack webpack-cli -g
. 我遵循其他答案中的建议,并通过
npm install webpack webpack-cli -g
全局npm install webpack webpack-cli -g
。
When I ran npx webpack
, I got 当我运行
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.
That's when I realized that I wasn't in the project folder... 那时我才意识到我不在项目文件夹中...
If you want to use npx
you don't need to install the webpack-cli globally. 如果你想使用
npx
你并不需要在全球范围内安装的WebPack-CLI。 There a good answer to this question in this stackoverflow page Difference between npx and npm? 在这个stackoverflow页面中,这个问题有一个很好的答案。npx和npm之间的区别是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.