Webpack command not found

Viewed 107073

I have installed webpack using

npm install -g webpack

and

npm install webpack 

I also installed webpack-dev-server

npm install -g webpack-dev-server

After completion of installation, I ran the command webpack but, it shows below error

webpack: command not found

I am not getting what is the error.

7 Answers

I needed to manually install:

npm install --save-dev webpack-cli

I guess its needed so that Angular CLI actually understands the commands related to Webpack.

In ubuntu u can try sudo apt install webpack

You need to be in proper folder to run webpack command.

What I mean by proper folder is folder in which you placed your installed module and module's package.json file.

Cause you installed it with -g parameter it is installed globally and you should find it in: ./node_modules/.bin/webpack.

Best practice is to install modules per project ( folder in which is project) not globally.

webpack -v: webpack command not found

node -v: v16.14.2

npm -v: 8.5.0

Tried to install webpack globally or locally and a lot of other ways to fix this issue but failed, below solution fixed my case (my case is a little bit special, I reset the prefix as below)

npm config set prefix "C:\Program Files\nodejs\npm_modules"

Solution: add the folder path xxx/npm_modules/ which included webpack.cmd to the System variable Path

enter image description here

How to find the folder path xxx/npm_modules/ which included webpack.cmd?

npm config ls

webpack.cmd in folder npm_modules, you will need this path to be added to System variable Path enter image description here

Related