Showing posts with label React Native. Show all posts
Showing posts with label React Native. Show all posts

Saturday, August 30, 2025

How to start 'metro' (React Native)

To See All React Native Articles: Index of Lessons in Technology

Good question 👍
The Metro bundler is the JavaScript packager that React Native uses. It must be running in the background for your app to load JS code.


🚀 How to start Metro bundler

  1. Go to your React Native project root (where package.json is).

    bash
    cd ~/Desktop/your_project_name
  2. Start Metro:

    bash
    npx react-native start
    • By default, Metro will run on port 8081.

    • Leave this terminal window open.

  3. In another terminal, build & install the app:

    bash
    npx react-native run-android

    or

    bash
    npx react-native run-ios

🌐 For wireless debugging

If you’re not using USB, run Metro with your laptop’s IP address:

bash
npx react-native start --host <your-laptop-ip>

Then configure your phone (Dev Settings → Debug server host & port) with:

makefile
<your-laptop-ip>:8081

⚡ Pro tip: If you already ran npx react-native run-android, Metro usually auto-starts in another tab. But if you closed it, just re-run npx react-native start.


Do you want me to also show you how to make Metro auto-restart whenever you run run-android, so you don’t have to open it manually each time?

Steps for Wireless Debugging

To See All React Native Articles: Index of Lessons in Technology

Yes 👍 wireless debugging is very handy in React Native, especially when your USB is unreliable. Here’s a step-by-step guide to set up wireless debugging with Android (ADB):


📱 1. Prerequisites

  • Android device (e.g., your Redmi A2 or Galaxy A06 5G)

  • Android 11+ (Wireless debugging is built into Developer Options)

  • Laptop with ADB installed (platform-tools package)

  • Both laptop and phone must be on the same Wi-Fi network


⚙️ 2. Enable Developer Options & Wireless Debugging

On your phone:

  1. Go to Settings → About phone → Tap Build number 7 times (to enable Developer Options).

  2. Go to Settings → Developer options.

  3. Turn on:

    • USB debugging (first time setup)

    • Wireless debugging


💻 3. First Pairing (via QR or Code)

  1. Run ADB on your laptop:

    bash
    adb pair ip:port
  2. On your phone → Developer options → Wireless debugging → Pair device with pairing code

    • It will show an IP:Port (like 192.168.0.105:37099)

    • And a 6-digit pairing code

  3. Enter it in terminal:

    bash
    adb pair 192.168.0.105:37099

    → If successful: Successfully paired to 192.168.0.105:37099


🔗 4. Connect ADB Over Wi-Fi

Now actually connect the device (different port from pairing one):

  1. Still in Wireless debugging, find IP address & Port for debugging (like 192.168.0.105:5555).

  2. Connect:

    bash
    adb connect 192.168.0.105:5555

    → You should see: connected to 192.168.0.105:5555

  3. Verify:

    bash
    adb devices

    Output should show:

    nginx
    List of devices attached 192.168.0.105:5555 device

🚀 5. Run React Native App Wirelessly

Now just run your app as usual:

bash
npx react-native run-android

It will install and debug over Wi-Fi without USB. 🎉


⚡ Troubleshooting

  • If adb connect fails → make sure phone & laptop are on same Wi-Fi.

  • If it disconnects after restart → you’ll need to re-pair.

  • Sometimes adb kill-server && adb start-server helps reset.


👉 Do you want me to also give you steps for QR pairing inside Android Studio (so you don’t need terminal at all), or you prefer ADB command-line only?

TESTING

(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached

(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ adb connect
adb: usage: adb connect HOST[:PORT]

(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ adb pair 192.168.1.2:44501
Enter pairing code: 652936
Successfully paired to 192.168.1.2:44501 [guid=adb-R9ZY3098GYX-8MEOzx]

(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ adb connect 192.168.1.2:36161
connected to 192.168.1.2:36161

(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ adb devices
List of devices attached
192.168.1.2:36161	device
adb-R9ZY3098GYX-8MEOzx._adb-tls-connect._tcp	device

React Native "init" command is deprecated

To See All React Native Articles: Index of Lessons in Technology
(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ npx react-native init ReadingAppForBrightOrange
Need to install the following packages:
react-native@0.81.1
Ok to proceed? (y) y


🚨️ The `init` command is deprecated.

- Switch to npx @react-native-community/cli init for the identical behavior.
- Refer to the documentation for information about alternative tools: https://reactnative.dev/docs/getting-started
Exiting...

FIX

(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ npx @react-native-community/cli init Reading_App_For_Bright_Orange
                                                          
               ######                ######               
             ###     ####        ####     ###             
            ##          ###    ###          ##            
            ##             ####             ##            
            ##             ####             ##            
            ##           ##    ##           ##            
            ##         ###      ###         ##            
             ##  ########################  ##             
          ######    ###            ###    ######          
      ###     ##    ##              ##    ##     ###      
   ###         ## ###      ####      ### ##         ###   
  ##           ####      ########      ####           ##  
 ##             ###     ##########     ###             ## 
  ##           ####      ########      ####           ##  
   ###         ## ###      ####      ### ##         ###   
      ###     ##    ##              ##    ##     ###      
          ######    ###            ###    ######          
             ##  ########################  ##             
            ##         ###      ###         ##            
            ##           ##    ##           ##            
            ##             ####             ##            
            ##             ####             ##            
            ##          ###    ###          ##            
             ###     ####        ####     ###             
               ######                ######               
                                                          

              Welcome to React Native 0.81.1!                
                 Learn once, write anywhere               

✔ Downloading template
✔ Copying template
✔ Processing template
✔ Installing dependencies
✔ Initializing Git repository

  
  Run instructions for Android:
    • Have an Android emulator running (quickest way to get started), or a device connected.
    • cd "/home/jain/Desktop/ws/react_native_apps/Reading_App_For_Bright_Orange" && npx react-native run-android
  
  

Issue with React Native Init Command

To See All React Native Articles: Index of Lessons in Technology
(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ npx react-native@latest init ReadingAppForBrightOrange
Need to install the following packages:
  react-native@0.81.1
Ok to proceed? (y) y
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'react-native@0.81.1',
npm WARN EBADENGINE   required: { node: '>= 20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@react-native/assets-registry@0.81.1',
npm WARN EBADENGINE   required: { node: '>= 20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@react-native/codegen@0.81.1',
npm WARN EBADENGINE   required: { node: '>= 20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@react-native/community-cli-plugin@0.81.1',
npm WARN EBADENGINE   required: { node: '>= 20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@react-native/gradle-plugin@0.81.1',
npm WARN EBADENGINE   required: { node: '>= 20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@react-native/js-polyfills@0.81.1',
npm WARN EBADENGINE   required: { node: '>= 20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@react-native/virtualized-lists@0.81.1',
npm WARN EBADENGINE   required: { node: '>= 20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-runtime@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-source-map@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@react-native/dev-middleware@0.81.1',
npm WARN EBADENGINE   required: { node: '>= 20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-config@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-core@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@react-native/debugger-frontend@0.81.1',
npm WARN EBADENGINE   required: { node: '>= 20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-babel-transformer@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-cache@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-cache-key@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-file-map@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-resolver@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-symbolicate@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-transform-plugins@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-transform-worker@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'ob1@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'metro-minify-terser@0.83.1',
npm WARN EBADENGINE   required: { node: '>=20.19.4' },
npm WARN EBADENGINE   current: { node: 'v18.19.1', npm: '9.2.0' }
npm WARN EBADENGINE }
/home/jain/.npm/_npx/dea611a43221eddd/node_modules/react-native/cli.js:147
- Switch to ${styleText(['grey', 'bold'], 'npx @react-native-community/cli init')} for the identical behavior.
              ^

TypeError: styleText is not a function
    at warnWithDeprecated (/home/jain/.npm/_npx/dea611a43221eddd/node_modules/react-native/cli.js:147:15)
    at main (/home/jain/.npm/_npx/dea611a43221eddd/node_modules/react-native/cli.js:219:7)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.19.1

FIX

(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 16555  100 16555    0     0   105k      0 --:--:-- --:--:-- --:--:--  105k
=> Downloading nvm from git to '/home/jain/.nvm'
=> Cloning into '/home/jain/.nvm'...
remote: Enumerating objects: 383, done.
remote: Counting objects: 100% (383/383), done.
remote: Compressing objects: 100% (326/326), done.
remote: Total 383 (delta 43), reused 179 (delta 29), pack-reused 0 (from 0)
Receiving objects: 100% (383/383), 392.12 KiB | 2.10 MiB/s, done.
Resolving deltas: 100% (43/43), done.
* (HEAD detached at FETCH_HEAD)
  master
=> Compressing and cleaning up git repository

=> Appending nvm source string to /home/jain/.bashrc
=> Appending bash_completion source string to /home/jain/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ nvm install 20
Downloading and installing node v20.19.4...
Downloading https://nodejs.org/dist/v20.19.4/node-v20.19.4-linux-x64.tar.xz...
################################################################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v20.19.4 (npm v10.8.2)
Creating default alias: default -> 20 (-> v20.19.4)
(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ nvm use 20
Now using node v20.19.4 (npm v10.8.2)
(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ node -v
v20.19.4

How can I start building a React Native app?

To See All React Native Articles: Index of Lessons in Technology

Great question 👍
Let’s go step by step so you can start building a React Native app from scratch.


🚀 Getting Started with React Native

1. Install Prerequisites

Before creating a project, make sure you have:

  • Node.js (LTS recommended – check with node -v)

  • npm (comes with Node) or yarn (npm install -g yarn)

  • Java JDK (for Android builds)

  • Android Studio (with SDK + emulator or real device)

  • (Optional) Watchman (for macOS/Linux, improves file watching)


2. Create a New Project

Run this in your terminal:

bash
npx react-native@latest init MyFirstApp

👉 This creates a folder MyFirstApp with everything set up.
Move into it:

bash
cd MyFirstApp

3. Run the App

▶️ On Android (emulator or real device)

bash
npx react-native run-android

(Phone must have USB debugging enabled OR emulator running)

▶️ On iOS (Mac only)

bash
npx react-native run-ios

4. Start the Development Server

React Native uses Metro bundler. Start it with:

bash
npx react-native start

This watches your code and reloads app changes automatically.


5. Edit Your App

Open App.js in your project folder.
Change the text inside the default screen, e.g.:

jsx
import React from 'react'; import { Text, View } from 'react-native'; const App = () => { return ( <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> <Text>Hello Ashish 👋, this is my first React Native app!</Text> </View> ); }; export default App;

Save → App reloads → You see your changes instantly.


6. Learn Core Components

Some essential components:

  • View → like a <div> (containers)

  • Text → display text

  • Image → display images

  • Button → basic buttons

  • TextInput → input fields

  • ScrollView / FlatList → lists and scrolling


7. Next Steps

  • Learn React Navigation (@react-navigation/native) for multiple screens

  • Use AsyncStorage or SQLite/Realm for local data

  • Try fetching APIs with fetch or axios


✅ With just this, you’ll have a working mobile app you can run on your Redmi A2 (or emulator) and keep improving step by step.


Do you want me to:
👉 (A) give you a minimal working "Hello World" project code you can paste directly, OR
👉 (B) outline a step-by-step practice roadmap (small milestones to learn React Native gradually)?

== == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==

Tests

(base) jain@jain-ThinkPad-T440s:~/Desktop/ws/react_native_apps$ node -v
v18.19.1