Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Sourcemap Page #3293

Merged
merged 6 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions docs/profile-hermes.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,10 @@ npx react-native profile-hermes [destinationDir]

### Enabling source map

A source map is used to enhance the profile and associate trace events with the application code. You can automatically generate a source map when converting the Hermes tracing profile to a Chrome tracing profile by enabling `bundleInDebug` if the app is running in development mode. This allows React Native to build the bundle during its running process. Here's how:

1. In your app's `android/app/build.gradle` file, add:

```groovy
project.ext.react = [
bundleInDebug: true,
]
```

:::info
Be sure to clean the build whenever you make any changes to `build.gradle`
You may read about source maps on the [source maps](sourcemaps.md) page.
:::

2. Clean the build by running:

```sh
cd android && ./gradlew clean
```

3. Run your app:

```sh
npx react-native run-android
```

### Common errors

#### `adb: no devices/emulators found` or `adb: device offline`
Expand Down
95 changes: 95 additions & 0 deletions docs/sourcemaps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
id: sourcemaps
title: Source Maps
---

Source maps help map a minified file back to an un-packaged state. This is common when investigating issues from release builds.
iBotPeaches marked this conversation as resolved.
Show resolved Hide resolved

This helps if you have a stacktrace like
iBotPeaches marked this conversation as resolved.
Show resolved Hide resolved

```text
TypeError: Cannot read property 'data' of undefined
at anonymous(app:///index.android.bundle:1:4277021)
at call(native)
at p(app:///index.android.bundle:1:227785)
```

The power of source maps allow tracing that line and column number back to the original source stacktrace.
iBotPeaches marked this conversation as resolved.
Show resolved Hide resolved

```text
TypeError: Cannot read property 'data' of undefined
at anonymous(src/modules/notifications/Permission.js:15:requestNotificationPermission)
at call(native)
at p(node_modules/regenerator-runtime/runtime.js:64:Generator)
```

This allows to triage release issues given a more accurate stacktrace.

Follow the instructions below to get started with source maps:

1. [Enable source maps on Android](sourcemaps.md#enable-source-maps-on-android)
2. [Enable source maps on iOS](sourcemaps.md#enable-source-maps-on-ios)
3. [Manual Symbolication](sourcemaps.md#manual-symbolication)
iBotPeaches marked this conversation as resolved.
Show resolved Hide resolved

## Enable source maps on Android

### Hermes

:::info
Source maps are built in Release mode by default. However, if `hermesFlagsRelease` is set - source maps will have to be enabled.
:::

If so, ensure the following is set in your app's `android/app/build.gradle` file.

```groovy
project.ext.react = [
enableHermes: true,
hermesFlagsRelease: ["-O", "-output-source-map"], // plus whichever flag was required to set this away from default
]
```

If done correctly - you may see the output location of the source map during Metro build output.

```text
Writing bundle output to:, android/app/build/generated/assets/react/release/index.android.bundle
Writing sourcemap output to:, android/app/build/intermediates/sourcemaps/react/release/index.android.bundle.packager.map
```

Development builds do not produce a bundle and thus already have symbols, but if the development build is bundled - you may enable source maps like:

Editing `android/app/build.gradle` file with:

```groovy
project.ext.react = [
bundleInDebug: true,
hermesFlagsDebug: ["-O", "-output-source-map"],
]
```
iBotPeaches marked this conversation as resolved.
Show resolved Hide resolved

## Enable source maps on iOS
iBotPeaches marked this conversation as resolved.
Show resolved Hide resolved

Source maps are built in Release mode by default. However, you might want to redirect the location of the source map for easier use.

If so, within Xcode head to the build phrase - "Bundle React Native code and images"
iBotPeaches marked this conversation as resolved.
Show resolved Hide resolved
iBotPeaches marked this conversation as resolved.
Show resolved Hide resolved

At the top of the file near the other export's, add an entry for `SOURCEMAP_FILE` to the preferred location and name. Like below:

```
export SOURCEMAP_FILE="$(pwd)/../main.jsbundle.map";

export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh
```

If done correctly - you may see the output location of the source map during Metro build output.

```text
Writing bundle output to:, Build/Intermediates.noindex/ArchiveIntermediates/application/BuildProductsPath/Release-iphoneos/main.jsbundle
Writing sourcemap output to:, Build/Intermediates.noindex/ArchiveIntermediates/application/BuildProductsPath/Release-iphoneos/main.jsbundle.map
```

## Manual Symbolication

:::info
You may read about manual symbolication of a stack trace on the [symbolication](symbolication.md) page.
:::
1 change: 1 addition & 0 deletions website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"fast-refresh",
"debugging",
"symbolication",
"sourcemaps",
"testing-overview",
"libraries",
"typescript",
Expand Down