How to run an old version of react native - 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

Related

Can't open React Native project

I have a problem with RN. I'm a newbie in RN, but I know a little bit of React.
So I tried to clone and open this project: https://github.com/mapbox/store-locator-react-native/
But I couldn't. I tried putting expo and running the project on an Android emulator, but even after I tried installing and uninstalling multiple packages, I always get some error. I also tried with npx react-native run-android but it doesn't work (in the folder with the project, not the base).
Could please someone tell me how to make this project work on my local machine and maybe even upgrade it to the newest RN?
Thanks
you have to navigate to your project
follow the steps
i am assuming your project on Desktop
launch terminal and write
cd Desktop/RNStoreLocatorExample
if you have IOS platform
do
npm install
cd ios
then
pod init
pod install
cd ..
react-native run-ios
or if you have android
write
react-native run-android
Hope it will work

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 ?

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

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

react-native run-android not working on ubuntu 16.04

i have a problem with react native in ubuntu, i have installed,
java jdk 8 (both javac --version) as well as echo $JAVA_HOME gives the proper output.
I have also installed android studio and set the android environment variables as well as the tools and echo $ANDROID_HOME gives output of the sdk location.
I have also installed gradle version 4.4.
I am unable to start the android app using react-native run-android. can any one let me know if i have missed something during installation.
And react-native as well as android studio works fine as I am currently using react-native start to start the metro builder as well as the other react-native cli commands. also android studio and gradle is also able to generate debug as well as release apks with no problems.
The error i get,
Scanning folders for symlinks in /home/igate-naveed/Documents/ReactNative/mobile-app-android/node_modules (16ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
First of all you need to create a project like this:
react-native init myProjectName
Then, start an emulator from Android Studio... Afterwards:
npm install && npm start
in your project directory, and from another terminal, inside your project directory, run :
react-native run-android
Is this working?
Instead of using the npm install manager, I used yarn and it worked for me. In your project directory, just do:
(project-directory)$ yarn
Update the gradle version.
Create new project:
react-native init projectname
Uninstall the npm pack.
Reinstall the npm pack again.
npm start
react-native start
react-native run-android