I am Learning React.js and i am using windows 8 OS.i have navigate to my root folder
1.Created the package.json file by npm init
2. install webpack by npm install -S webpack.now webpack has been downloaded to my modules folder
3. install webpack globally by typing npm install webpack -g
4. i am also having a webpack.config.js in my root folder which contains the source and ouput directory
5. when i type the webpack command i am getting the below error.
webpack is not recognized as a internal or external command,operable program or batch file
We also experienced this problem and I like all the answers that suggest using a script defined in
package.json
.For our solutions we often use the following sequence:
npm install --save-dev webpack-cli
(if you're using webpack v4 or later, otherwise usenpm install --save-dev webpack
, see webpack installation, retrieved 19 Jan 2019)npx webpack
Step 1 is a one-off. Step 2 also checks
./node_modules/.bin
. You can add the second step as a npm script topackage.json
as well, for example:and then use
npm run build
to execute this script.Tested this solution with npm version 6.5.0, webpack version 4.28.4 and webpack-cli version 3.2.1 on Windows 10, executing all commands inside of a PowerShell window. My nodejs version is/was 10.14.2. I also tested this on Ubuntu Linux version 18.04.
I'd advise against installing webpack globally, in particular if you are working with a lot of different projects each of which may require a different version of webpack. Installing webpack globally locks you down to a particular version across all projects on the same machine.
Install WebPack globally
Add webpack command as an npm script in your package.json.
Then run
When the webpack is installed it creates a binary in ./node_modules/.bin folder. npm scripts also looks for executable created in this folder
I got the same error, none of the solutions worked for me, I reinstalled node and that repaired my environment, everything works again.