“反应本机”不能被识别为内部或外部命令、可操作程序或批处理文件

我最近开始用原生反应。我在 Facebook 网站上用这个教程安装它,一两天内一切都很顺利,直到这条信息出现:

'react-native' is not recognized as an internal or external command,
operable program or batch file.

除了卸载所有东西然后重新开始,没有什么是可以工作的。环境良好,可以工作(npm,Choco,等等)。我还尝试过删除和添加 response-national 到环境变量、重新启动和在管理员模式下运行 cmd,但是到目前为止还没有任何尝试。我应该补充一下,我使用的是 Windows 1064位。

170328 次浏览

I get the same error right off the bat on Windows 10 running in cmd window in adminstrator mode, however there is also a bash shell version of react-native that worked for me in a git bash window.

cmd:----------------------------------------------
C:\Users\David\Documents\react>where react-native
C:\Users\David\AppData\Roaming\npm\react-native
C:\Users\David\AppData\Roaming\npm\react-native.cmd


C:\Users\David\Documents\react>react-native init AwesomeProject
'react-native' is not recognized as an internal or external command,
operable program or batch file.




git bash:----------------------------------------
David@CYBER-PC ~/Documents/react
$ react-native init AwesomeProject
This will walk you through creating a new React Native project in        c:\Users\David\Documents\react\AwesomeProject
Installing react-native package from npm...
Setting up new React Native app in  c:\Users\David\Documents\react\AwesomeProject
AwesomeProject@0.0.1 c:\Users\David\Documents\react\AwesomeProject`-- react@15.3.1


To run your app on iOS:
cd c:\Users\David\Documents\react\AwesomeProject
react-native run-ios
- or -
Open   c:\Users\David\Documents\react\AwesomeProject\ios\AwesomeProject.xcodeproj in Xcode
Hit the Run button
To run your app on Android:
Have an Android emulator running (quickest way to get started), or a device connected
cd c:\Users\David\Documents\react\AwesomeProject
react-native run-android

I had the same issue and tried the following but didnt work 1) Adding npm path to my Environment variables; both system and user 2) Re install npm and react-native-cli

Both didn't work for me, im using Windows 10;

Solution that worked for me is to install react-native-cli globally You can install it globally by using the below command:

npm install -g react-native-cli

Hope that helps you! Cheers :)

I uninstalled node.js and then reinstalled it, and it worked like a charm

npm install -g react-native-cli

use node.js stable version or recommended version.

You need to setup the npm path in your environment variables. Please look at the images down below

enter image description here

Then follow the command : for installing -g ( global ) for cli in your system

npm install -g react-native-cli

If you are following the getting started guide for Windows/Android, they recommend installing nodejs via Chocolatey. But Chocolatey likes to have administrator rights when it installs things. If you're just a regular user, this seems to interfere with how npm installs react-native-cli. In my case, the react-native command was only recognized when I launched a command prompt as admin.

What I did to fix:

  1. launched command prompt as admin
  2. uninstalled react-native-cli globally: npm uninstall -g react-native-cli
  3. uninstalled nodejs via Chocolatey: choco uninstall nodejs

Now, as a regular user without admin rights:

  1. installed nodejs via the nodejs website (not Chocolatey)
  2. installed react-native-cli globally: npm install -g react-native-cli
  1. just uninstall the node.js and reinstall it..
  2. then install the cli package typing command

npm install -g react-native-cli..

now you are ready to make your project.

To make project open a folder from your drive wherever your folder is located.

Then type command

react-native init albums

it will create a project for you inside your directory.

None of the above mentioned solutions worked for me. What did work was to remove nodejs, and reinstall it via Chocolatey with the following command:

PS > choco install -y nodejs.install python2 jdk8


> npm install -g react-native-cli
C:\Users\user\AppData\Roaming\npm\react-native ->
C:\Users\user\AppData\Roaming\npm\node_modules\react-native-cli\index.js
+ react-native-cli@2.0.1
added 41 packages from 15 contributors in 4.528s

On window 10, nodejs>11 global node libraries seems to be installed in C:\Users\your_user_name.npm-global. So you need to set the variable to point to that path

I had to add the %APPDATA%\npm folder to my PATH on Windows 10. Global modules are installed there.

Your system or user environment PATH variable was edited, you can uninstall NodeJs and install it again or add the below path to the end of PATH variable into user variables the restart the Windows :

C:\Users\[USER-NAME]\AppData\Roaming\npm

this should work.

I had problems because of this strange mistake.

I checked to see if it was globally loaded again

I didn't delete all packages

I even deleted C:\Users[USER-NAME]\AppData\Roaming\ npm manually, but there was no solution.

The only thing that is the solution is to use the current version of node.js.

I had this problem also becuase I restored my files from a previous OS installation. My problem was a wrong prefix in my C:\Users\user_name\.npmrc file.

Run npm config list and make sure that all your npm config variables are leading to the correct file paths. Delete the .npmrc file if you want have it to go back to the defaults. That's what I did and react-native command is working for me again.

I hope this helps.

uninstall nodejs completely(restart your pc) and reinstall it using chocolatey and follow other commands from https://facebook.github.io/react-native/docs/getting-started.

worked perfectly fine for me!

Even if you have installed react-native globally and still get the same try adding path of npm module (C:\Users\your user name\AppData\Roaming\npm) to system variables instead of user variables.

If uninstalling and installing again the npm did not work on you, try adding %APPDATA%\npm to path (Environment variables) then quick reboot/restart. System Reboot should really be part of the process. This worked on my end.

Install :

npm install -g react-native-cli

Uninstall :

npm uninstall -g react-native-cli

i have no clear idea but below steps worked for me.

  1. delete Node Modules
  2. Uninstall react-native cli. This is Recommended in the react-native Documentation

"If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues."

npm uninstall -g react-native-cli
  1. clean gradlew. in your project folder, go to the android folder by typing cd android and run gradlew clean

  2. move back to your project folder cd .., then run

    npx react-native run-android

these steps worked for me. took some time when running first time.

I know it's too late, anyway

  • Make sure you've added the path of the NPM in system variable rather than user variable in the System Environment Variables.

PATH : C:\Users\user_name\AppData\Roaming\npm

You can simply use npx react-native <command> it will work

Open a the command prompt and type: npm config list:

enter image description here

Get the path underlined in red and add it your system path (change two back slashes into one), for example: C:\Users\YOURNAME\AppData\Roaming\npm.

This solved the issue for me

I just wrote "react-native -v" to console to check have I still react-native and then just I wrote "react-native run-android" again and this time it worked. Yes just that. React native is terrible technology.

npm install -g react-native-cli

But dont forget to restart command promprt

Looks like I have uninstalled react native cli by mistake, I tried all answers mentioned above, but the below command worked for me.

npx react-native run-android.

Solution

I was facing 'react-native' is not recognized as an internal or external command,operable program or batch file error when I was running react-native start in VsCode.

I Solved it by running npm install -g react-native-cli in PowerShell

Steps to follow

  1. run PowerShell as admin (important step)
  2. run running npm install -g react-native-cli in PowerShell
  3. close VsCode and rerun it
  4. that's all!

I solve this problem by running

npm install -g react-native-cli

then another error appears

Command run-android unrecognized.

I fixed this error by

npm install

Use npx before your command

  npx react-native

Not just

  react-native

if you faced the same issue as me just type :

npm i react-native

then try to create a new project as its recommended by the react native doc by typing : npx react-native init yourProjectName

this should resolve your problem

hope this was helpful