Local Development Setup
This page includes tips for developers working on Metro itself, including how to test your changes within other local projects.
Testing Metro Changes inside a React Native Project
When developing Metro, running your iterations against a local target project can be a great way to test the impact of your changes end-to-end.
Our recommended workflow is to use yarn link to register local metro packages within your development clone and then hot-switch to these versions in the consuming project. These instructions cover linking a local Metro clone with a bare workflow React Native app (i.e. having run npx react-native init MetroTestApp).
.
└── Development
├── metro # metro clone
└── MetroTestApp # target project
-
Use
yarn linkin yourmetroclone to register local packagesFrom inside our
metroclone,yarn linkis responsible for registering local package folders to be linked to elsewhere.We recommend using
npm exec --workspacesto register all packages in themetrorepo — these can be individually linked into the target project later.npm exec --workspaces -- yarn link -
Use
yarn linkto replace Metro packages in your target projectFrom inside our target project folder,
yarn link <package-name>can be used to apply our registeredmetropackages for that project only.# Links 3 packages
yarn link metro metro-config metro-runtimeNote: At mininum, the
metroandmetro-runtimepackages need to be linked. -
Configure Metro
watchFoldersto work with our linked packagesBecause
yarn linkhas included files outside of the immediate React Native project folder, we need to inform Metro that this set of files exists (as it will not automatically follow the symlinks). Add the following to yourmetro.config.js:+ const path = require('path');
module.exports = {
+ watchFolders: [
+ path.resolve(__dirname, './node_modules'),
+ // Include necessary file paths for `yarn link`ed modules
+ path.resolve(__dirname, '../metro/packages'),
+ path.resolve(__dirname, '../metro/node_modules'),
+ ],
...
};Run Metro
Now we should be able to run Metro within our target project. Remember to restart this command after any code changes you make to
metroor to the target project'smetro.config.jsfile.yarn react-native start -
(Optional) Clean up with
yarn unlinkIf you want to restore the remote (i.e. production npm) versions of
metropackages in your target project, step 2 (and 1) can be repeated withyarn unlink.
Debug Logging
Metro uses the debug package to write logs under named debug scopes (for example: Metro:WatchmanWatcher). Set the DEBUG environment variable before starting Metro to enable logs matching the supplied pattern.
The snippet below provides a pattern matching all Metro-defined messages.
DEBUG='Metro:*' yarn metro serve