Zsh: command not found: webpack

EDIT: Don't do this. Bad practice.

Easy way. Install it globally.

npm i -g webpack

If you will work with webpack, install webpack-dev-server too

npm i -g webpack-dev-server

I recommend you first learn a bit about npm and then webpack.


having webpack installed locally, you could also use:

$(npm bin)/webpack

instead of:

./node_modules/.bin/webpack

Installing node modules globally is a quick solution, but i recommend to add ./node_modules/.bin to the path variable and try to understand, what's the problem.

Execute

~ export PATH="./node_modules/.bin:$PATH"

Afterwards you can simply use all packages installed locally in your project. Also commands like mocha or eslint can be executed without installing these packages globally. There are several good explanations out there maybe also read this answer.


There is no need to install webpack globally.

Try my way:

First, in your package.json file, add this:

"scripts": {
   "start": "webpack"
},

Then, in your terminal, run

$npm start

Another quick way: Just run (Yes, it is 'npx')

$npx webpack

That's all.

Tags:

Zsh

Npm

Webpack