73

I have two different ReactNative-Projects:

  • a) a project from januar 2016
  • b) a complete new react-native project from now (march 20th 2016)

Within the new project the cli tool of react-native contains the command "run-ios" next two "run-android", but not on the older project from januar 2016. On the older one there is not "run-ios" command available:

$ react-native run-ios
Command `run-ios` unrecognized
Usage: react-native <command>

I already ran "react-native upgrade" without any issues.

How can i get the command "run-ios" also in older projects?

delete
  • 18,144
  • 15
  • 48
  • 79
  • 3
    If you're like me and you tried `npx react-native run-ios`, make sure you are actually inside the project folder.. – Dror Bar Dec 29 '20 at 08:18

15 Answers15

127

Just update the version of react native in your project with the following command:

$> npm install --save react-native@latest
itinance
  • 11,711
  • 7
  • 58
  • 98
42

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.

Dimitris
  • 13,480
  • 17
  • 74
  • 94
35
 $ react-native run-ios

If you get this kinda error:

"Command run-ios unrecognized. Make sure that you have run npm install and that you are inside a react-native project".

In terminal, make sure you are inside a react-native project directory.

Execute this cmd:

$ react-native -v
react-native-cli: 2.0.1
react-native: n/a - not inside a React Native project directory
$ npm update
$ react-native -v
react-native-cli: 2.0.1
react-native: 0.44.0
$ react-native run-ios
Balasubramanian
  • 5,274
  • 6
  • 33
  • 62
26

This may sound silly, but make sure you cd to your project directory. If that fails then perform the npm install in the other answers.

Fostah
  • 2,947
  • 4
  • 56
  • 78
6

I found a solution that works for me. Update the version of react native in your project:

npm install --save react-native@latest 

then upgrade your npm version

npm i npm@latest -g

then move directory folder 1 level up, type

cd ..

make a new react-native installation folder

react-native init NewProject

then go to your project folder(NewProject), after that

react-native run-ios

should work fine.

cela
  • 2,352
  • 3
  • 21
  • 43
Ramon
  • 61
  • 1
  • 1
2

This happens when the project has an older version of react native. You can update the react version or for people who do not want to upgrade, just open the .xcodeproj file in iOS dir and hit the play button in the Xcode.

vincent mathew
  • 4,278
  • 3
  • 27
  • 34
1

In my case, it was an issue with the package.json file. I deleted a section during a test. I recover a previous file with the deleted section and everything was working again.

1

this works for me

sudo npm install -g react-native-cli --force 

then

react-native run-ios
Abdullah Tahan
  • 1,963
  • 17
  • 28
1

In my case, I am using monorepo with multiple packages in a single repo. I solved this error by

  • Deleting the packages/myapp/node_modules
  • running yarn install from the project root. Not inside packages
  • its solved. Now can run yarn ios or yarn android commands

Note: For autolinking libraries you need to have all of your dependencies in root package.json file also copied to packages/myapp/package.json file. See https://github.com/react-native-community/cli/blob/master/docs/autolinking.md#how-can-i-use-autolinking-in-a-monorepo

Example:


  "dependencies": {
    "@react-native-community/datetimepicker": "^3.5.2",
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/native": "^5.9.4",
    "@react-navigation/stack": "^5.14.5",
    "@reduxjs/toolkit": "^1.6.0",
    "@voximplant/react-native-foreground-service": "^2.0.0",
    "axios": "^0.21.1",
    "babel-eslint": "^10.0.3",
    "eslint-config-airbnb": "^18.0.1",
    "eslint-plugin-import": "^2.18.2",
    ...
    ...

but make sure NOT TO COPY

    "react-native-cli": "^any version",

otherwise react-native-cli would collide and you will continue to see error like

Command `run-android` unrecognized. Make sure that you have run `npm install` and that you are inside a react-native project.
error Command failed with exit code 1.

or

Command `run-ios` unrecognized. Make sure that you have run `npm install` and that you are inside a react-native project.
error Command failed with exit code 1.
Shiva
  • 11,485
  • 2
  • 67
  • 84
0

I created a brand new react-native project using
$ react-native init projectName
and ran from root of the project
$ react-native run-ios
Everything worked fine and iOS simulator fired up as expected.

Than I installed prop-types node module using npm install prop-types --save. Re-ran $ react-native run-ios and ran into this error Command run-ios unrecognized

Solution: From the root of my project, removed node_module and re-installed modules using npm. Commands below

$ rm -rf node_modules/
$ npm install
$ react-native run-ios
RC_02
  • 3,146
  • 1
  • 18
  • 20
0

For me, Xcode was already running.

Close the Xcode and then in the terminal, make sure you are inside a react-native project directory and then execute react-native run-ios command

Mohit
  • 885
  • 9
  • 7
0

For me, the only thing that worked was to checkout again my repository from zero and run:

npm install -g react-native-cli yarn 
yarn  
git submodule update --init --recursive
carla
  • 1,970
  • 1
  • 31
  • 44
0

What caused this for me was running npm install --save axios when actually the system was previously using yarn instead of npm.

To solve this, instead of deleting the node_modules folder, which can lead to more problems, and if you prefer to run npm anyway or don't have a preference either way, the error should have instructed for you to run npm install. If you literally follow those instructions, you will be able to run: react-native run-ios afterwards.

Daniel
  • 14,004
  • 16
  • 96
  • 156
0

I also fell in this error and the reason was
I was using yarn link command in wrong folder

Sultan Ali
  • 2,497
  • 28
  • 25
0

Delete the node-modules. Its because the packages are not installed.

rm -rf node_modules npm install

then run your project

react-native run-ios