Failed to start the app. Run CLI with --verbose flag for more details - react-native

Error: Command failed: adb shell am start -n com.getgroceryapp/com.getgroceryapp.MainActivity
at makeError (F:\desuvit\projects\workingbranch\MobileApp\node_modules\execa\index.js:174:9)
node version: 12.4.0
npm version: 6.14.7
Using these command for running the app: 1)react-native run-android or npx react-native run-android
also same error
after i upgraded to v12.18.3(node version) also same error.
but i'm trying to run the project getting above error
please help me
advance thanks....

Open Android Studio File -> Project Structure -> Gradle Settings -> Gradle JDK
and set up as
Embedded JDK
This worked for me after trying so many other options.

If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues:
npm uninstall -g react-native-cli #react-native-community/cli

Related

Error when trying to do 'expo build:android'

In the Terminal I get the following error after running the expo build:android command:
Error: Can't find react-native in package.json dependencies
Error: react-native is not installed. Please run `npm install` or `yarn` in your project directory.
There is an error with your project. See above logs for information.Error: There is an error with your project. See above logs for information.
Terminal error picture
I have already tried to update npm version, npm install, and I also tried npm install -g eas-cli
Are there certain steps anyone thinks I should do?
Follow below guide
Delete node_modules folder in root folder
npm install (If you are using yarn use yarn install)

npx react-native run-android error Unrecognized command "run-android"

I'm rather new to the whole RN world, my project ran just fine, but after I added a library (npm install)
I get this error
Unrecognized command "run-android".
When I do
npx react-native run-android
From a lot of readings about it what I tried so far is
npm uninstall -> npm install
delete node modules folder -> npm install
delete node modules -> delete package.json.lock-> npm install
npx react-native link
All didn't help , any ideas on how to fix this ?
Install the run-android command by running below command
npm i react-native-run-android

Cannot run program "npx": error=2, No such file or directory when running React Native app

I have been working with react-native project in another pc and it has been working correctly. Now I cloned project to another device where I have react-native installed since I work with other project and I cannot run it.
When I run react-native run-android I get this error:
Cannot run program "npx": error=2, No such file or directory
I'm using Android Studio 4 on Mac OS Catalina 10.15.6.
I solved the problem by running Android Studio with bellow command on console.
$ open -a "Android Studio.app"
Simple steps you need to go through to make it work with npx
sudo npm uninstall -g react-native-cli
sudo npm i -g npx
npx react-native run-android
More detailed explanation why this is happenig
Issue was that Facebook is not using anymore react-native-cli as they are using npx.
As stated in Facebook page:
If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues.
So i had to run sudo npm uninstall -g react-native-cli to remove react-native-cli
They also say that npx is shipped with nodejs but that wasn't my case.
React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using npx, which ships with Node.js.
So I had to install it using sudo npm i -g npx
After installing npx then just need to run npx react-native run-android.
Be aware of npx before react-native run-android
Now you don't have any command react-native now we only have 'npx' and react-native run-android is just a parameter for npx. For ex. to start metro we should run npx react-native start
I had the same issues, so I followed these steps:
Start by installing the latest version of Android Studio (Don't delete the old version, just copy paste that to another directory or in my case I just added the Android Studio 3.2.1 that I had to a folder called olderAndroidStudio, on mac).
Make sure you don't click on import settings from Existing.
Follow along the installation, and complete it.
Build and Run, app runs without any problems.
I additionally uninstalled react-native-cli using the method given in the accepted answer.
In my case, I just quit Android Studio and reopened, and the error was gone.
Maybe throw in a ./gradlew clean for goo measure.
I solved it by finding the command that was throwing error and ran it directly
node -e "console.log(require('react-native/cli').bin)"
which outputs a path, something like
$HOME/my-app/node_modules/#react-native-community/cli/build/bin.js
then I pasted that path in android/app/build.gradle
project.ext.react = [
entryFile: "index.js",
enableHermes: true, // clean and rebuild if changing
cliPath: "$HOME/my-app/node_modules/#react-native-community/cli/build/bin.js" // <--- add this
]

How to fix error in "Copying template" when making project?

I'm generating a new project using React-Native in Command Prompt but I get an error when I use the following command:
react-native init Style
This is the result I get:
√ Downloading template
× Copying template
error Error: Cannot find module 'C:\Users\User\AppData\Local\Temp\rncli-init-template-srEvW0\node_modules\react-native\template.config'
error EBUSY: resource busy or locked, rmdir 'D:\FUSI\React Native\Style'. Run CLI with --verbose flag for more details.
Error: EBUSY: resource busy or locked, rmdir 'D:\FUSI\React Native\Style'
at Object.rmdirSync (fs.js:684:3)
at rmdirSync (D:\FUSI\React Native\node_modules\fs-extra\lib\remove\rimraf.js:276:13)
at Object.rimrafSync [as removeSync] (D:\FUSI\React Native\node_modules\fs-extra\lib\remove\rimraf.js:252:7)
at Object.initialize [as func] (D:\FUSI\React Native\node_modules\react-native\node_modules#react-native-community\cli\build\commands\init\init.js:295:26)
at process._tickCallback (internal/process/next_tick.js:68:7)
How can I fix this error?
Mustafa AK had it right. What worked for me is adding the --npm flag at the end of the command.
I followed the tutorial exactly how it was laid out on the React website and was running into the same error. For whatever reason, if you have yarn and npm installed the command to create a new project will not work. So you have to add the --npm flag to get it to only use npm and this will work.
npx react-native init AwesomeProject --npm
This Same error comes with me. But I solved by following ways...
First, uninstall the node from your system and download the latest version of node and install it.
2.after installation of the latest version of node you need to write the command in your command prompt
npm install -g react-native-cli
Now go to your project directory
cd your-react-native-project directory
now create your react-native project
react-native init your-project-name.
https://stackoverflow.com/a/71725307/16114216
Be sure uninstall global react-native/cli as described react-native tutorials
Try to use --npm end of init command if you had yarn and npm both.
npx react-native init MyApp --template react-native-template-typescript --npm
Note: If you have both yarn and npm installed on your machine, React Native CLI will always try to use yarn, so even if you use npx utility, only react-native executable will be installed using npm and the rest of the work will be delegated to yarn. You can force usage of npm adding --npm flag to the command.

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