Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install webpack-cli?

Tags:

webpack

I have installed webpack 4.5.0.

When I try to run webpack, it complains that it wants webpack-cli.

If I run npm install webpack-cli I get the following error:

The CLI moved into a separate package: webpack-cli
Would you like to install webpack-cli? (That will run npm install -D webpack-cli) (yes/NO)yes
npm WARN deprecated [email protected]: Package no longer supported. Contact [email protected] for more info.
npm WARN [email protected] requires a peer of webpack@^4.0.0 but none is installed. You must install peer dependencies yourself.

+ [email protected]
updated 1 package in 14.175s
{ Error: Cannot find module 'webpack-cli'
    at Function.Module._resolveFilename (module.js:543:15)
    at Function.Module._load (module.js:470:25)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at runCommand.then.result (/usr/local/lib/node_modules/webpack/bin/webpack.js:62:14)
    at <anonymous>
at process._tickCallback (internal/process/next_tick.js:118:7) code: 'MODULE_NOT_FOUND' }

Anybody has seen this and fixed it somehow?

like image 698
mircealungu Avatar asked Apr 17 '18 14:04

mircealungu


People also ask

What is webpack CLI npm?

webpack CLI provides a flexible set of commands for developers to increase speed when setting up a custom webpack project. As of webpack v4, webpack is not expecting a configuration file, but often developers want to create a more custom webpack configuration based on their use-cases and needs.

Is webpack CLI required?

If you're using webpack v4 or later and want to call webpack from the command line, you'll also need to install the CLI.


Video Answer


2 Answers

This is happening because while webpack-cli might be installed globally, it is not installed in your current project, and somehow the project isn't capable of using the globally-installed version.

I fixed this by running npm install webpack-cli in the relevant project directory.

like image 126
Andrew Koster Avatar answered Sep 29 '22 04:09

Andrew Koster


It worked for me by installing below modules:

npm i -g webpack-cli

npm install --save-dev webpack

npm install --save-dev webpack-dev-server

like image 42
rameshP Avatar answered Sep 29 '22 06:09

rameshP