"react-native eject": Unrecognized command "eject" - react-native

I am trying to recreate ios and android folders for my react-native project. As far as I know this is done with the command:
react-native eject
But I get the error:
error Unrecognized command "eject".
I am doing something wrong? How should I recreate android and ios folders?
react-native-cli: 2.0.1

npm i react-native-eject
npm i #react-native-community/cli
react-native eject
will generate the both android and ios folder

It did work in 0.59.9. This threw me too this morning after I upgraded to 0.60. Apparently you now have to run react-native upgrade --legacy true. react-native eject was much easier IMHO.

yarn add react-native-eject
react-native eject
This two-line of code solved my problem with the eject error.

Nikita is 100% correct. If the project was initialized in expo running react native eject will "eject" the project from the expo dependencies (and expo environment) and create a standalone react native project outside the expo environment. This typically adjusts the dependencies in the pakage.json file.
The command exists as a part of expo.
To initialize a project from scratch react-native init will create android and ios folders. Also ensure if you have cloned the directory to run either npm install or yarn to install the dependencies.
If the project was initialized the way I imagine yours was the commmand you are looking for would be one of the following:
react-native run ios or react-native run ios --device
react-native run android or react-native run android --device

For RN projects, which are initiated by react-native init there is no such command, by default RN is using metro bundler instead of web-version of React, where you can configure Parcel/Webpack/Rollup or run create-react-app where actually you can eject.
This question is suitable for expo where you can actually eject, if you need some native modules that are not included in expo.
Try to use expo

react-native eject and upgrade --legacy true aren't working for me.
In the end, I just created a new blank RN project and this had an ios folder. Copied the folder over to my existing project and ... seems to work.

Run npm i react-native-eject
Run npm i #react-native-community/cli --force
Note: use npx instead of npm
npx react-native eject
cd android
./gradlew.bat installDebug
cd..
npm run android

Related

I want to start with react native without expo method.. i found this error

I got this error when i am trying to run my app in original device, everything according to react-native documentation
Try running your app with the yarn command, otherwise run npm-doctor to make sure all your packages are updated and fixed.
otherwise try installing dependencies for expo using :
npm install -g yarn
yarn add global react-native
yarn add global react-native-cli
react-native init sample
here's a quick link to the npm-doctor documentation:
https://docs.npmjs.com/cli-commands/doctor.html
Also here's some tutorial on running react-native app using yarn command:
How do I create a React Native project using Yarn?
I find this solution .. i just replace 6.2 with 6.3
in android/gradle/ gradle-wrapper.properties
distributionUrl=https://services.gradle.org/distributions/gradle-6.3-all.zip

How to run an old version of react native

Just a quick question, how to run an existing older version of react native project. Lets say version 0.59.10 , without upgrading it. what would be the command line commands. Thanks
You should navigate to project directory (if you aren't yet)
cd PATH_TO_PROJECT_DIRECTORY
run the following command to install the dependencies
npm install
then if the react-native version is 0.59.10 and lowers you should also run the command below to link the dependencies to your native android and ios project.
react-native link
and then run one the following commands based on your device
for android
react-native run-android
for ios
react-native run-ios

react-native eject not working for react-native 0.60.0

Is react-native eject is not working anymore ? is it completely removed from the react-native? I am using react-native version 0.60.0.
I can't even find it in the react-native help.
Please check the image for more reference:
Same here. In this moment, have a brand new backup of your project and then copy the android and ios folder, is the better way to regenerate those folders... unfortunately
UPDATE
react-native upgrade --legacy true
Firstly you would need to install react-native-eject then you can run react-native eject.
Simply do these:
npm i react-native-eject
or
yarn add react-native-eject
then run:
react-native eject
Yes, the eject command was removed from react-native recently (March 28, 2019).
React Native had this command in the previous version. Running this command will check if the ios and android directories exist and then rebuild whichever one is missing.
react-native eject <=0.59.0
Now you should use the react-native upgrade --legacy true command to back up your android folders or ios as the case may be as this command will replace your files.
react-native eject has been deprecated use npx react-native eject its working
eject isn't part of react-native, but rather expo. To eject, you can run:
npm run eject

Android 'react-native-gesture-handler' error

When I follow the instruction by the react-navigation website : https://reactnavigation.org/docs/en/getting-started.html.
react-native link react-native-gesture-handler
and then change the MainActivity.java like it asks.
Then run react-native run-android, and error pop up :
error React Native CLI uses autolinking for native dependencies, but the following modules are linked manually:
react-native-gesture-handler (to unlink run: "react-native unlink react-native-gesture-handler")
This is likely happening when upgrading React Native from below 0.60 to 0.60 or above. Going forward, you can unlink this dependency via "react-native unlink " and it will be included in your app automatically. If a library isn't compatible with autolinking, disregard this message and notify the library maintainers.
my react-native version :
react-native-cli: 2.0.1
react-native: 0.60.0
However, when I follow the instruction, to unlink the library
use : react-native unlink react-native-gesture-handler
The app successfully built, but now it pops up another error in the app :
null is not an object (evaluating 'rngesturehandlermodule.direction')
I tried a lot of solution in a lot of websites, like
undefined is not an object (evaluating 'RNGestureHandlerModule.State'
non of them is working for me
Looks like this is to do with the new autolinking feature in RN 0.60.
For iOS
To fix for now just add the following podspec for RNGesureHandler to ios/Podfile
pod 'RNGestureHandler', :podspec => '../node_modules/react-native-gesture-handler/RNGestureHandler.podspec'
Then in the ios directory run pod install to install it.
For Android
Path: android/app/src/main/java/com/projectname/MainApplication.java
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
....
protected List<ReactPackage> getPackages() {
// Add additional packages you require here
// No need to add RnnPackage and MainReactPackage
return Arrays.<ReactPackage>asList(
....
new RNGestureHandlerPackage()
);
}
Have a good day.
I'm not sure about what went wrong, but very possibly because of the react-native-cli that upgraded from below 0.60.0 to above it.
BEFORE 0.60.0 when running react-native run-android, the command will run a metro packager, along with building the android app, and then run the app that connect to the metro packager.
That's why in the past, we only run one command "react-native run-android" to run the project.
But AFTER 0.60.0 when running react-native run-android, the command will only build the android-app, and run the app to connect to the metro packager.
I saw a command prompt blinked once, might also be how the command start the metro packager went wrong and the packager just closed itself somehow.
Also as for the problem with react-native link react-native-gesture-handler I believe it is the new feature of react-native 0.60.0 to autolink library, so manual linking of library is not necessary anymore. As a lot of the library provider might need to start providing auto-linking features, or might face the same error, not just react-native-gesture-handler.
Temporary Solution until someone fix the react-native-cli to run the metro packager again:
Open 2 command prompt instead of 1. And run the command below on each of the command prompt:
react-native start
react-native run-android
You might want to run the first command first and wait for it to be ready before running the 2nd.
Otherwise, you app might turn out to be blank.
Source : I tried it myself by creating new project and running the command as mentioned by the question.
What you can do is, first uninstall react-native-gesture-handler.
Then delete IOS and Android folder.
Then run below command.
1.react-native upgrade --legacy true // to recover ios and android folder.
2.npm install react-native-gesture-handler
3.react-native link
4.react-native run-android
5.react-native run-ios
Also update your MainActivity.java file , follow official website:
https://kmagiera.github.io/react-native-gesture-handler/docs/getting-started.html
Did you run react-native run-android or react-native run-ios ?

Error while running react-native-app-auth in react-native 0.60

So, I used react-native init [project-name] to create one react-native project. It installed the latest version of native, 0.60. Then I installed react-native-app-auth.
After than I started the metro server using react-native start.
But when I ran react-native run-android, the compiler gave me some errors.
Task :react-native-app-auth:compileDebugJavaWithJavac FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
I've tried to link it manually using react-native link react-native-app-auth.
Don't have any code. It's just some simple configuration.
I expect it to run smoothly, without any errors.
I am getting error after running react-native run-android
https://gist.github.com/ElavanResu/4555dc94f460681aaf051c2a3852effa
You can try to jetify the node_modules until react-native-app-auth updates his repository making it compatible with RN 0.60.
1) npm install --save-dev jetifier
2) npx jetify
3) npx react-native run-android
4) npx jetify
as said in: https://facebook.github.io/react-native/blog/2019/07/03/version-60#androidx-support