Metro, the Bundler
When you run npx expo start for Sprout, a terminal fills with a QR code and a line that says Metro is waiting. Your phone never opens your source files directly. Something has to collect them and hand them over. That something is Metro.
The rule
Metro gathers every file into one bundle and serves it to the app.
Metro is the JavaScript bundler made for React Native. It does three jobs:
- Resolve. Starting at your entry file, it follows every
importandrequire, including packages innode_modulesand images inassets/. - Transform. It compiles JSX and TypeScript into plain JavaScript the engine can run, using Babel.
- Serve. In development it runs a local server (port 8081 by default) and sends the bundle to the app on your phone or simulator.
npx expo start # starts Metro for an Expo project
npx expo start --clear # starts Metro with an empty cacheIn a bare CLI project the command is npx react-native start, and the cache flag is --reset-cache.
Because Metro watches your files, a save triggers a quick rebuild of just what changed, and Fast Refresh pushes it to the running app. For a release build, Metro produces one bundle that is packed inside the app, so the store version needs no server.
Metro also understands platform extensions: if both Header.ios.js and Header.android.js exist, import Header from './Header' picks the right one for each platform. You will use that in the platform section.
The shortcut
When the app shows old code or a "module not found" error, walk Metro's three jobs in order: resolve, transform, serve. The problem is almost always at one of those steps.
Resolve?
Metro could not find the file. Check the path: the file is
components/PlantCard.js.
The trap is thinking the phone app "contains" your code during development. It does not; it downloads the bundle from Metro. If your phone and laptop are on different networks, the app cannot reach Metro and loading fails.
Drills
Answer fast — trust the rule.
What is Metro's main job?
Which port does Metro's development server use by default?
Sprout keeps showing old behaviour after you install a new package. What is a sensible first fix in an Expo project?
During development, where does the app on your phone get its JavaScript from?
Remember
- Metro gathers every file into one bundle and serves it to the app.
- Debug in order: resolve, transform, serve.
- Trap: in development the phone needs to reach Metro on your computer.
