React Native: Command `run-ios` unrecognized - react-native

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?

Just update the version of react native in your project with the following command:
$> npm install --save react-native#latest

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.

$ 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

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.

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.

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.

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

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.

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

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

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

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.

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

Related

Error while creating react-native cli project

Error:
Error: Couldn't find the "C:\Users\Admin\AppData\Local\Temp\rncli-init-template-oScLDz\node_modules\react-native\template.config.js file inside "react-native" template. Please make sure the template is valid. Read more: https://github.com/react-native-community/cli/blob/master/docs/init.md#creating-custom-template
Screenshot:
I have tried with npm using and it worked.
npx react-native init YourAwesomeProject --npm
After that
I have uninstalled yarn completely. Because you can install libraries using npm. So I have removed the yarn using
npm uninstall -g yarn
You can try:
Remove the global react-native CLI: npm uninstall -g react-native-cli or yarn global remove react-native-cli
And run again npx react-native init YourAwesomeProject
or
Run npx react-native-cli init YourAwesomeProject
Maybe these links can help:
https://github.com/react-native-community/cli#about
How to fix "Can not find module ".../template.config" error in React Native
surely you have your root a file or folder .yarn/ package.json package-lock.json
Remove them and try again rm -rf .yarn/ package.json .yarn/ package-lock.json

eject command not found in create-react-app -- how to add to package.json?

I get this error after installing create-react-app, and trying to run "npm run eject"
eject: command not found.
How do I edit package.json to run the command I found in the documentation?
I found a work-around: run the script, manually, found in node_modules/react-scripts/scripts/eject.js.
node ./node_modules/react-scripts/scripts/eject.js
facebook's github indicates that the global install of create-react-app would interfere with CRA installation; and so I ran:
npm rm -g create-react-app
as suggested on facebook's github here:
https://github.com/facebook/create-react-app/issues/8088#issuecomment-562189517
(and then reinstall CRA)
You have to install
https://github.com/ramyareye/react-native-eject
yarn add react-native-eject
yarn react-native eject
Instead of npm try with npx
npx react-scripts eject
Above command worked for me.

Why sould one init a react-native project with npx?

Today I tried to do things differently, and launched a react-native project with npx, and went into troubleshooting issues like react-native command not found, are you sure this is an android project, etc. while things were easier with expo and react-native init.
So I'm wondering, according to you, what are the advantages, what does npx more ?
npm:
npm create-react-app my-app executes the local create-react-app package from your machine, so you first have to install it globally on your system with npm install -g create-react-app.
npx:
If you run npx create-react-app my-app and don’t have create-react-app globally on your system, it will get downloaded and not installed globally.
As you are getting "react-native command not found", first make sure to have react-native cli installed globally. For that,
npm i -g react-native-cli
Then create your react-native project.

why do I get react-native command not found error on windows pc?

I am very new to React-native and I have a sample project when I tried running the command react-native run-android. I got an error command not found.
in the current directory do
react-native -v
you will get the following
react-native -v
react-native-cli: version
react-native: version
if it shows command not found the n you have not installed react native in the directory. Do a npm init in new folder and try installing a new react native project there
by doing npm install -g react-native-cli
Follow the steps to add path variable react-native.
You're good to go.
Have you run 'npm install' (without parameters) in the project directory? That'll install the dependencies for your project.
Details here: https://docs.npmjs.com/cli/v6/commands/npm-install
1.Try to install globally npm install -g react-native-cli 2.add path of npm module (C:\Users\your user name\AppData\Roaming\npm) to system variables instead of user variables

React Native 0.45 - Cannot find entry file index.ios.js

I just updated my react native project to version 0.45
and when using this command : react-native run-ios on the root of this project
I am getting this error :
Cannot find entry file index.ios.js in any of the roots ....
and i can see that the server is trying to look for JS files in
Looking for JS files in
/Users/someUser/Code/ReactTest/node_modules/react-native/packager
when using this command : npm run start -- --root .
i can see that the server is looking for js file in the correct location
Looking for JS files in
/Users/someUser/Code/ReactTest
and every thing is working from here
why the react-native run-ios is try to look in the wrong location ?
I ran into this issue today. As noted here it has been corrected as of version 0.45.1, but this turned out to be a red herring for me.
The most telling problem in my case was that index.ios.js didn't actually exist anywhere in my project, only in some places in node_modules. It turns out that, because I'd initialised the project with the create-react-native-app command, I had to:
npm run eject
You can read more about the eject command here.
If you still have issues, try the below.
Check your dependency versions. Here are my RN packages:
"react": "16.0.0-alpha.12"
"react-test-renderer": "16.0.0-alpha.12"
"react-native": "^0.45.1"
Update your dependency managers. These worked for me:
$ yarn --version
0.18.1
$ npm --version
4.6.1
Clean your cache(s). WARNING - CONTAINS rm -rf, COPY WITH CARE.
watchman watch-del-all
rm -rf ./node_modules
yarn cache clean
rm -rf $TMPDIR/react-*
yarn install
npm start -- --reset-cache
After that last npm start, hit CTRL+C and ensure there are no dormant npm processes running in the background. Then, try react-native run-ios again.
The react-native launched new release 0.45 a few days back. So, the commands to create a react-native application and running locally have many differences.
npm install -g create-react-native-app
Then run the following commands to create a new React Native project called "AwesomeProject":
the new way of creating a react-native application as follows
create-react-native-app AwesomeProject
cd AwesomeProject
npm start
Please follow the official documentation for creating an application and running the application on locally. hope the below link will help you.
https://facebook.github.io/react-native/docs/getting-started.html
Once you've set these up, you can launch your app on an Android Virtual Device by running npm run android, or on the iOS Simulator by running npm run ios(macOS only).
Enjoy, Happy coding :)