Reputation: 69
I'm trying to test a custom Webpack configuration. I've read that instead of typing node ./node_modules/webpack/bin/webpack.js
, I can use 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:
user@comp:~/> npx webpack-cli
npx: installed 489 in 19.186s
Cannot find module 'webpack'
Upvotes: 5
Views: 5838
Reputation: 69
I followed the advice in the other answers and installed Webpack globally with npm install webpack webpack-cli -g
.
When I ran npx webpack
, I got
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...
Upvotes: 0
Reputation: 635
You can install webpack and webpack-cli packages globally so you won't need to use node ./path/to/webpack
:
$ npm install webpack webpack-cli -g
This will install webpack globally on your machine. Then in your project folder run
$ webpack
Upvotes: 1
Reputation: 1589
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
npx webpack
Upvotes: 1