sh: webpack: command not found
Problem sh: webpack: command not found
This issue of sh: webpack: command not found is very common among programmers in the JSON language. To use this module one needs to install it in their system. To install this module run the following commands as shown below:
npm install -g webpack
If the above command does not work one can try another one which is shown here.
npm install webpack
One needs to also install webpack-dev-server. The code for the same is:
npm install -g webpack-dev-server
It may be possible one may get this error even after installing all the above-mentioned modules. The error is shown below:
Solution
One of the solutions to the above problem is the folder./node modules/.bin/ contains your webpack. So you should carry out the following command:
./node_modules/.bin/webpack
It is advised to install Webpack and Webpack-dev-server locally as a best practice.
yarn add webpack webpack-dev-server --dev
# or
npm install webpack webpack-dev-server --save-dev
Then, you can include these lines in the package.json file’s scripts section.
"scripts": {
"build": "webpack --progress --colors",
"start": "webpack-dev-server --progress --colors"
}
After doing all these steps the final step is to run the following commands:
npm start
npm run build
Another solution is to manually install the package on your computer.
npm install --save-dev webpack-cli
The webpack script is located in [node installed path]/lib/node modules/webpack/bin/ and can be used using an absolute path, by adding it to the PATH environment variable, or by creating a symbolic link, among other methods.
Also Read: Built-in Functions of Python