''react-native' is not recognized as an internal or external command, operable program or batch file
I recently started with react-native. I install it using the tutorial on the Facebook site and everything works well for a day or two until this message comes up:
'react-native' is not recognized as an internal or external command,
operable program or batch file.
Nothing works except uninstalling everything and starting all over again. The environments are ok and work (npm, choco, etc.). I have also tried removing and adding react-native to environment variables, restarting, and running cmd in administrator mode, but nothing so far. I should add that I use windows 10 64-bit.
Solution 1:[1]
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 :)
Solution 2:[2]
You can simply use npx react-native <command>
it will work
Solution 3:[3]
npm install -g react-native-cli
But dont forget to restart command promprt
Solution 4:[4]
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.
Solution 5:[5]
You need to setup the npm path in your environment variables. Please look at the images down below
Then follow the command : for installing -g ( global ) for cli in your system
npm install -g react-native-cli
Solution 6:[6]
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
[email protected] c:\Users\David\Documents\react\AwesomeProject`-- [email protected]
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
Solution 7:[7]
npm install -g react-native-cli
Solution 8:[8]
I had to add the %APPDATA%\npm
folder to my PATH on Windows 10. Global modules are installed there.
Solution 9:[9]
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
Solution 10:[10]
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:
- launched command prompt as admin
- uninstalled
react-native-cli
globally:npm uninstall -g react-native-cli
- uninstalled
nodejs
via Chocolatey:choco uninstall nodejs
Now, as a regular user without admin rights:
- installed
nodejs
via the nodejs website (not Chocolatey) - installed
react-native-cli
globally:npm install -g react-native-cli
Solution 11:[11]
I uninstalled node.js and then reinstalled it, and it worked like a charm
Solution 12:[12]
- just uninstall the
node.js
and reinstall it.. - 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.
Solution 13:[13]
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
+ [email protected]
added 41 packages from 15 contributors in 4.528s
Solution 14:[14]
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.
Solution 15:[15]
use node.js stable version or recomnended version
Solution 16:[16]
i have no clear idea but below steps worked for me.
- delete Node Modules
- 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
clean gradlew. in your project folder, go to the android folder by typing
cd android
and rungradlew clean
move back to your project folder
cd ..
, then runnpx react-native run-android
these steps worked for me. took some time when running first time.
Solution 17:[17]
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
Solution 18:[18]
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.
Solution 19:[19]
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!
Solution 20:[20]
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.
Solution 21:[21]
I know it's too late, anyway
- Make sure you've added the path of the NPM in
system variable
rather thanuser variable
in theSystem Environment Variables
.
PATH : C:\Users\user_name\AppData\Roaming\npm
Solution 22:[22]
Open a the command prompt and type: npm config list
:
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
Solution 23:[23]
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.
Solution 24:[24]
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 25:[25]
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
- run PowerShell as admin (important step)
- run running
npm install -g react-native-cli
in PowerShell - close VsCode and rerun it
- that's all!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow