72

I've installed react-native-cli globally:

npm install -g react-native-cli

Then run:

react-native init AwesomeProject
cd AwesomeProject

I got the following structure:

-- AwesomeProject   
---- node_modules      
------ react-native    

When I run react-native run-android I get an error:
Command run-android unrecognized. Did you mean to run this inside a react-native project?

When I run react-native start I get the same.

react-native -v
prints:
react-native-cli: 0.2.0
react-native: n/a - not inside a React Native project directory

What I'm doing wrong?

ravibagul91
  • 20,072
  • 5
  • 36
  • 59
Sergey Onishchenko
  • 6,943
  • 4
  • 44
  • 51

38 Answers38

68

the answer is easy nad it is not because of any bug at all.

make sure you are in correct directory 

if in current directory there is not any react native app ,it gives you this error

afshar003
  • 765
  • 6
  • 6
54

What caused this for me was running npm install --save [package] when actually the system has previously been using yarn instead of npm.

To solve this I just deleted the node_modules folder and ran: yarn install and after that react-native run-ios (or android) works fine.

(This is a duplicate of React Native: Command `run-ios` unrecognized)

remo
  • 880
  • 2
  • 14
  • 32
Dimitris
  • 13,480
  • 17
  • 74
  • 94
32

I just ran "yarn" with no arguments and it fixed it.

Doug Voss
  • 1,012
  • 1
  • 14
  • 11
  • @sergey-onishchenko This should be the answer ... I usually clone a react-native project and run it before installing dependencies. – vijayst Mar 13 '19 at 12:43
25

Please try this command:

npm install --save react-native
Max Dalton
  • 100
  • 2
  • 10
Vijendra patidar
  • 1,444
  • 1
  • 14
  • 24
  • 1
    I comment this to remember which command use to solve this problem if happens for a third time, thanks this works for me :) – Enrique San Martín Nov 30 '22 at 04:30
  • 1
    This did the trick for me. I had some errors and deleted my `package.json` file and `node_modules` directory and for some reason `$ npm install` wasn't doing anything. This command did the trick. Thanks! – Forrest Feb 19 '23 at 19:45
10

The problem was that I terminated init command because it looked like hanged without errors (even 24 hours later). To fix this I updated nodejs and npm to newer versions. Once I have done it react-native init was executed properly and there is no more problem with react-native run-android.

Sergey Onishchenko
  • 6,943
  • 4
  • 44
  • 51
10

react-native run-android is unrecognized

Make sure that you have installed npm or use in your project directory

npm install
Pang
  • 9,564
  • 146
  • 81
  • 122
7

you have to update your npm. To do that

npm install npm@latest -g
cain
  • 709
  • 2
  • 10
  • 18
6

try "yarn install". It will install the missing files in node_modules

It worked for me

Kaveri
  • 151
  • 1
  • 6
6

This can be caused by a couple of issues.

!!! Before trying each solution remember to open a new terminal since you might have old paths sources from your .bashrc file. !!!

  1. You did not install the contents of the project. In order to solve this you have to install the node_modules by typing:

    npm install or yarn install

  2. You are coming back to a previously installed project after doing some funny things with your react-native installation and global configurations. (Upgrading the library, upgrading node doing something with globally installed node_modules).

You should clean all your caches and project modules

Here you can find a command to do all these things in one line (remember to replace npm with yarn accordingly): https://gist.github.com/jarretmoses/c2e4786fd342b3444f3bc6beff32098d

  1. Your global installation of react-native or react-native-cli is broken. In this case simply reinstall your libraries globally.

    npm: npm install -g react-native && npm install -g @react-native-community/cli

    yarn: yarn global add react-native && yarn global add @react-native-community/cli

twboc
  • 1,452
  • 13
  • 17
5

I think the command you are looking for is react-native run-android.

cd into your project and run this command where all you js files are present and not in the android folder.

It will run a package manager, do not close that. Also you need to have an emulator or a device connected to your computer with usb debugging enabled.

Hope the answer helped

Ronak Khandelwal
  • 301
  • 2
  • 16
  • react-native run-android - that is the command that I have used. And I did it from within AwesomeProject directory. – Sergey Onishchenko Jun 03 '16 at 11:12
  • hmmmm could you do a ls in that directory and post the results. Also are you sure that the init got completed without any issues? – Ronak Khandelwal Jun 03 '16 at 11:15
  • I have terminated the execution of the init because It looked like it finished it's job. I will try it again. Actually, should it take so long? – Sergey Onishchenko Jun 03 '16 at 11:24
  • First time it takes long enough to feel like nothing is happening Ideally you'll get a index.android.js and index.ios.js and other such files let it run to completion go out for a walk and then try again! – Ronak Khandelwal Jun 03 '16 at 11:35
5

Step 01 : Make sure that you are in right directory
Step 02 : npm install run this command
Step 03 : npm audit fix run this to fix issues

Try deleting node_modules folder and then run the commands again

Luis Paulo Pinto
  • 5,578
  • 4
  • 21
  • 35
4
npx react-native run-android

Use of npx will pick local npm node_modules directory

spacedev
  • 1,086
  • 13
  • 13
4

Do npm install then run react-native run-android

Antoni
  • 1,316
  • 2
  • 16
  • 42
Ali Shan
  • 49
  • 1
  • 1
3
  • Make sure you go into the directory having package.json

  • If you have deleted nodemodules try "npm install".

  • And don't forget the "init" in "react-native init MyApp". "init"
    initializes the package.json.

Viraj Singh
  • 1,951
  • 1
  • 17
  • 27
3

You can solve this by yarn or npx:

yarn react-native run-android
npx react-native run-android
SHR
  • 7,940
  • 9
  • 38
  • 57
Ahmed Shahin
  • 102
  • 4
2

Everything has already tried like me? Then try again once "Yarn install after deleting node_modules". It worked for me.

1

I did everything correct while setting up, but was unable to run the android code. Just make sure while running the command react-native run-android that, you are inside the AwesomeProject folder created by the react-native init AwesomeProject command.

The folder by default for my PC was under C:\Windows\system32\AwesomeProject in Windows.

Hope it helped for the first timers :)

sud007
  • 5,824
  • 4
  • 56
  • 63
1

You need to update the project with the latest version of react-native. Just run this command.

npm install --save react-native@latest

Sahil Jain
  • 3,649
  • 2
  • 14
  • 16
1

If you guys have latest react native version and facing this error

"UNRECOGNIZED COMMAND run-android".

then run follow these steps it will definitely help you.

Step: 1 -> create a new file "react-native.config.js" in the project root directory.

Step : 2 -> Inside "package.json" you have "assets" array inside "rnpm" object cut these assets from this and paste in your "react-native.config.js". i-e:

module.exports = {
assets: ['./assets/fonts'],
}

Step : 3 -> Remove "rnpm" object from "package.json".

Step : 4 -> Replace your "scripts" with below mentioned "scripts" inside "package.json"

"scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "android:prod": "npx react-native run-android --variant=release",
    "ios:prod": "react-native run-ios --configuration Release"
  }

That's it Happy Hacking..............

Avinash Dalvi
  • 8,551
  • 7
  • 27
  • 53
1

In my case, I forgot to run npm install before running react-native run-android. I know this is a silly mistake but it may help.

0

Uninstall react-native from global

$ npm uninstall -g react-native

Then

Install react-native to global

$ npm install -g react-native-cli
noufalcep
  • 3,446
  • 15
  • 33
  • 51
Elvin Lee
  • 9
  • 1
0

That worked for me

react-native run-android


 start [options]                    starts the webserver
run-ios [options]                  builds your app and starts it on iOS simulator
run-android [options]              builds your app and starts it on a connected Android emulator or device
new-library [options]              generates a native library bridge
bundle [options]                   builds the javascript bundle for offline use
unbundle [options]                 builds javascript as "unbundle" for offline use
eject [options]                    Re-create the iOS and Android folders and native code
link [options] [packageName]       links all native dependencies (updates native build files)
unlink [options] <packageName>     unlink native dependency
install [options] <packageName>    install and link native dependencies
uninstall [options] <packageName>  uninstall and unlink native dependencies
upgrade [options]                  upgrade your app's template files to the latest version; run this after updating the react-native version in your package.json and running npm install
log-android [options]              starts adb logcat
log-ios [options]                  starts iOS device syslog tail
dependencies [options]             lists dependencies
info [options]                     Get relevant version info about OS, toolchain and libraries

They have made some unnoticeable changes. For instance run-android(now) run android(before).

Farhan
  • 1,445
  • 16
  • 24
0

Try to delete "package-lock.json" and re-run "npm install", then try your command, It should work

0

I got this error because I had parenthesis in the path "(" and ")". Possibly this error is thrown for other special characters as well.

0

Ensure you run the command in the projects' terminal, preferably the Android IDE. Run the adb devices to know your active devices as well

Raphael Amponsah
  • 549
  • 6
  • 13
0

If your package.json file is containing any comment then this error is comes. So remove all comments from package.json and then run command it will work.

Also try to run command npm install --save then it will log if other error there. If any others error also there, then first fix it and then run command it will work.

Kishan Bharda
  • 5,446
  • 3
  • 30
  • 57
0

In Android Studio click in Tools -> SDK Manager -> in System Settings click in Android SDK -> choose tab SDK Tools, then enable Android SDK command line tools (lasted). It work for me!

0

Open your React Native Project Root Directory and locate android -> app -> build -> intermediates -> signing_config -> debug -> out -> signing-config.json

Delete signing-config.json file

And rebuild your application.

react-native run-android
Xấu Xa
  • 1
  • 1
  • 1
  • 3
0

First thing you need to delete node_mouldes and package.lock.json and do yarn install after that if you're using Windows OS you need to use PowerShell not git bash and write this command "react-native run-android"

Yazan Najjar
  • 1,830
  • 16
  • 10
0

Install npm again to latest react-native init project_name cd project_name open android studio the same android folder inside your project_name react_native run_android will work now

rubal islam
  • 339
  • 3
  • 5
0

for the last time your project was working fine and now you got this error suddenly and you have Node modules already installed then just trynpm install --save react-native this work for me

Pravin Ghorle
  • 606
  • 7
  • 7
0

In my case, there was an extra comma in the Package.json in the "dependencies" section. "use-is-mounted-ref": "^1.4.0",

This made react to not be able to update, install anything. Last line shouldn't have any comma

M.J
  • 1
  • 1
0

I got this because I accidentally installed a react template and not a react-native template

Mr Heelis
  • 2,370
  • 4
  • 24
  • 34
-1

For my case, I just forgot to access the project folder using "cd" command after generating the project.

Ayoub Laazazi
  • 540
  • 7
  • 15
-1

I forgot to change the directory first after run react-native init command. When I ran command inside the react-native project directory it worked post that run the command npx react-native run-ios or run-andoid, it will work.

error Unrecognized command "run-android". info Run "react-native --help" to see a list of all available commands.
user3004692
  • 23
  • 1
  • 4
-1

First, ensure you have configured environment variables correctly. If yes, then make sure Powershell/cmd runs in the project's directory and node js is configured correctly.

-2

Okay, I tried many of the tough solutions, also many mentioned above, But yarn install did the job greatly.

yarn install

Irshad Babar
  • 1,311
  • 19
  • 26
-3

Firstly you have run cmd line as a admin before enter "npx react-native init <your_project_name>" command. Then try other solutions.

  • what do you exactly mean bu admin? user needs to navigateto project root folder and run npm run command or react-native cli command – pavle Oct 02 '20 at 18:58