Fix 'unrecognized command run-ios' in React Native

By

Learn how to fix the unrecognized command run-ios error in React Native, which happens when you run npx react-native run-ios outside the project folder.

~~~

The “unrecognized command run-ios” error usually means you’re running the command outside a React Native project folder. cd into the project, run it again, and it works.

Here’s the full story. I was starting a new React Native project and I ran the command

npx react-native run-ios

to start it.

I got an error back with this line in it:

unrecognized command "run-ios"

I could not figure this out, until I realized I was running this command in my home folder.

Instead, this needs to be run from inside the project’s folder.

cd into the React Native project, and this error should go away and your React Native app should start successfully.

Why does this happen?

The React Native CLI loads its commands from the project you’re standing in. Commands like run-ios and run-android come from packages installed in the project’s node_modules.

When you run the command in your home folder, there’s no project. The CLI still starts, but it has no platform commands registered. So from its point of view, run-ios is a command that doesn’t exist. The error message says “unrecognized command” instead of the more helpful “you’re in the wrong folder”.

Still failing inside the project?

If you get the same error while you are in the project folder, check two things.

First, make sure the dependencies are installed. A fresh clone of a repository has no node_modules folder yet:

npm install

Then run npx react-native run-ios again.

Second, make sure you’re in the folder that contains the package.json with the react-native dependency. In a monorepo it’s easy to end up one level too high, or inside the ios subfolder. Run ls and look for package.json, plus the ios and android folders. That’s the right place to run the command from.

~~~

Related posts about react-native: