webpack is not recognized as a internal or externa

2020-01-26 04:17发布

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

标签: npm webpack
22条回答
聊天终结者
2楼-- · 2020-01-26 04:28

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

查看更多
该账号已被封号
3楼-- · 2020-01-26 04:30

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

%USERPROFILE%\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;%USERPROFILE%\AppData\Roaming\npm\", "User")

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

Hope it helps.

查看更多
狗以群分
4楼-- · 2020-01-26 04:31

you have to install webpack and webpack-cli in the same scope.

npm i -g webpack webpack-cli

or,

npm i webpack webpack-cli

if you install it locally you need to call it specifially

node_modules/.bin/webpack -v
查看更多
看我几分像从前
5楼-- · 2020-01-26 04:31

For me it worked to install webpack separately. So simply:

$npm install
$npm install webpack

I'm not sure why this should be necessary, but it worked.

查看更多
放荡不羁爱自由
6楼-- · 2020-01-26 04:33

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
查看更多
神经病院院长
7楼-- · 2020-01-26 04:33

The fix for me was locally installing webpack as devDependency. Although I have it as devDependencies it was not installed in node_modules folder. So I ran npm install --only=dev

查看更多
登录 后发表回答