webpack is not recognized as a internal or external command,operable program or batch file

匿名 (未验证) 提交于 2019-12-03 03:08:02

问题:

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

回答1:

I had this issue for a long time too. (webpack installed globally etc. but still not recognized) It turned out that I haven't specified enviroment variable for npm (where is file webpack.cmd sitting) So I add to my Path variable

c:\Users\Me\AppData\Roaming\npm\ 

If you are using Powershell, you can type the following command to effectively add to your path :

[Environment]::SetEnvironmentVariable("Path", "$env:Path;c:\Users\Me\AppData\Roaming\npm\", "User") 

IMPORTANT : Don't forget to close and re-open your powershell window in order to apply this.

Hope it helps.



回答2:

Better solution to this problem is to install Webpack globally.

This always works and it worked for me. Try below command.

npm install -g webpack 


回答3:

As an alternative, if you have Webpack installed locally, you can explicitly specify where Command Prompt should look to find it, like so:

node_modules\.bin\webpack 

(This does assume that you're inside the directory with your package.json and that you've already run npm install webpack).



回答4:

npm install -g webpack-dev-server will solve your issue



回答5:

Just run your command line (cmd) as an administrator.



回答6:

Add webpack command as an npm script in your package.json.

{     "name": "react-app",     "version": "1.0.0",     "scripts": {       "compile": "webpack --config webpack.config.js"     } } 

Then run

npm run compile

When the webpack is installed it creates a binary in ./node_modules/.bin folder. npm scripts also looks for executable created in this folder



回答7:

I've had same issue and just added the code block into my package.json file;

 "scripts": {    "build": "webpack -d --progress --colors"  } 

and then run command on terminal;

npm run build 


回答8:

Sometimes npm install -g webpack does not save properly. Better to use npm install webpack --save . It worked for me.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!