Debugging multiple MiniApps
Debugging individual MiniApps (running standalone) works similar to debugging regular React Native apps. See Debugging for more information.
The rest of this guide focuses on a setup to debug multiple MiniApps with the help of the ern start command and a local Composite.
Prerequisites
All prerequisites of React Native and Electrode Native
The VS Code React Native Tools extension
Setup
Step 1: Prepare working directory
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:
Step 2: Link MiniApps
Run ern link
in each MiniApp directory.
The ern link 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.
Step 3: Initialize parent project
This is necessary for the React Native Tools extension to work properly.
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:
Step 4: Create a debug configuration
Visual Studio Code
This configuration will be used to attach the VS Code debugger (actually the React Native Tools debug adapter) to the native application.
Follow the instructions in Launch configurations to create a new launch configuration and open the resulting launch.json
file.
Manually add a sourceMapPathOverrides
section to configure sourcemaps:
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.
We can now start debugging with the help of the ern start command.
Debugging
Step 1: Create a composite
In order to debug and step through the code, we require a locally generated Electrode Native Composite inside of the workspace
directory.
Pass an absolute path as the --compositeDir
parameter to ern start
:
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 Cauldron. See ern start --help
for more information.
Once composite generation is done, we should have the following structure:
Step 2: Open the project and set breakpoints
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.
Step 3: Attach the debugger
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.
Step 4: Enable JS Debugging in the app
In the native application, bring up the React Native developer menu, 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.
Last updated