Debugging multiple MiniApps
Last updated
Last updated
Debugging individual MiniApps (running standalone) works similar to debugging regular React Native apps. See for more information.
The rest of this guide focuses on a setup to debug multiple MiniApps with the help of the command and a local .
All prerequisites of and
The VS Code extension
Inside a new directory (e.g. workspace
), clone all MiniApps that you want to debug.
In this example, for two MiniApps details-miniapp
and list-miniapp
, the directory structure should look like this:
Run ern link
in each MiniApp directory.
Run yarn init --yes
(or npm init --yes
) in the parent directory (workspace
) to create a package.json
file. Then add the React Native dependencies:
Use the same versions of react
and react-native
that are used by the MiniApps (in this example React Native 0.60.6).
The structure should now look like this:
Note that the package name of the MiniApp could be different from the directory name in the workspace folder.
At this point our directory structure should look like:
The basic setup is now complete. If you need to add more MiniApps, clone them into the workspace
directory, run ern link
, and add a corresponding mapping entry to sourceMapPathOverrides
configuration.
Pass an absolute path as the --compositeDir
parameter to ern start
:
Once composite generation is done, we should have the following structure:
Open the workspace
directory in VS Code (if you have not done so already) and launch the native application (if it is not already running). It may have been launched automatically by ern start
.
Now you may set breakpoints in the JavaScript code of the MiniApps.
To attach VS Code to the React Native debugger, run the Attach to packager debug configuration. Make sure the ern start
command has completed and is still running in the background. You will notice an indicator that will keep spinning until the next step is completed.
The command is needed to map the source location between the composite and the MiniApp directory, but also to ensure that any changes to the MiniApp directory are propagated to the Composite.
This is necessary for the extension to work properly.
This configuration will be used to attach the (actually the debug adapter) to the native application.
Follow the instructions in to create a new launch configuration and open the resulting launch.json
file.
Manually add a sourceMapPathOverrides
section to configure :
We can now start debugging with the help of the command.
In order to debug and step through the code, we require a locally generated inside of the workspace
directory.
The MiniApps to include in the composite can be passed using the --miniapp
(or -m
) flag. If no other options are defined, the ern start
command requires an active . See ern start --help
for more information.
In the native application, bring up the , and turn on JS Debugging by tapping Debug (Android) or Debug JS Remotely (iOS). This will result in attaching to the Visual Studio Code debugger. If debugging was already turned on in the native app, disable it first, then re-enable it. In VS Code you should now see that the debugger was attached. Check if the breakpoints are triggered in the sources of details-miniapp
and list-miniapp
, and debug the MiniApps in VS Code.