Reputation: 2930
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.
Upvotes: 53
Views: 154278
Reputation: 3
I just reinstalled webpack globally using this command and it works for me
npm install -g webpack
Upvotes: 0
Reputation: 865
I ran into this problem within an old project I returned to after a while (that used to run properly). This fixed the issue:
npx webpack
The version information is: node v18.16.1 (npm v9.5.1)
and I use a MacOS.
Upvotes: 2
Reputation: 1109
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
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
Upvotes: 0
Reputation: 1566
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.
Upvotes: 0
Reputation: 641
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.
Upvotes: 8
Reputation: 1241
If you want to use global installation, you can find webpack script in [node_installed_path]/lib/node_modules/webpack/bin/
, you can use with absolute path, adding to PATH
environment variable, or symbolic link, etc.
If you want to use local installation, find it in ./node_modules/.bin/
.
I recommand using local installation (for same reason about babel).
Upvotes: 1
Reputation: 4332
As a good practice is recommended to install webpack
and webpack-dev-server
locally, more info here.
yarn add webpack webpack-dev-server --dev
# or
npm install webpack webpack-dev-server --save-dev
Then you can add these lines to your scripts section in your package.json file.
"scripts": {
"build": "webpack --progress --colors",
"start": "webpack-dev-server --progress --colors"
}
and finally
npm start
npm run build
Note: You need to have a
webpack.config.js
in the root folder to make it run correctly.
Upvotes: 29
Reputation: 13247
Your webpack exists in ./node_modules/.bin/ folder . So you should execute this command :
./node_modules/.bin/webpack
Check out the answer in this thread .
Upvotes: 66