React Native: Command `run-ios` unrecognized

Viewed 59864

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?

15 Answers

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.

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.

this works for me

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

then

react-native run-ios

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

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

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

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.
Related