microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
extract-uplicate-code-as-a-common-base-class

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

README.md

1198lines · modecode

1# React Native Tools
2
3[![Build Status](https://dev.azure.com/vscode-webdiag-extensions/VS%20Code%20WebDiag%20extensions/_apis/build/status/%5BUnit%20tests%5D%20vscode-react-native%20%5Bmaster%5D?branchName=master)](https://dev.azure.com/vscode-webdiag-extensions/VS%20Code%20WebDiag%20extensions/_build/latest?definitionId=60&branchName=master)
4
5Stable:
6![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/msjsdiag.vscode-react-native?color=deep%20green&label=Version)
7![Visual Studio Marketplace Rating (Stars)](https://img.shields.io/visual-studio-marketplace/stars/msjsdiag.vscode-react-native?label=Rating)
8
9Preview:
10![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/msjsdiag.vscode-react-native-preview?color=deep%20green&label=Version)
11![Visual Studio Marketplace Rating (Stars)](https://img.shields.io/visual-studio-marketplace/stars/msjsdiag.vscode-react-native-preview?label=Rating)
12
13## React Native Tools Preview
14
15The extension has a [nightly version](https://marketplace.visualstudio.com/items?itemName=msjsdiag.vscode-react-native-preview) which is released on a daily basis at 9 PM PST on each day that changes occur.
16To avoid conflicts, if both extensions are installed - only stable version will be activated. So to use the preview version it is needed to disable or remove the stable version and reload VS Code.
17
18## Package extension locally
19
20You can not only download React Native Tools in the marketplace, but can also package your extension `.vsix` installation file by yourself locally. Following [this documentation](https://github.com/microsoft/vscode-react-native/blob/master/CONTRIBUTING.md#build-the-project) to package and install your React Native Tools to get the latest updates.
21
22## About the extension
23
24This VS Code extension provides a development environment for React Native and Expo projects.
25Using this extension, you can **debug your code and quickly run `react-native` or `expo` commands** from the command palette.
26
27![React Native features](resources/images/react-features.gif)
28
29<!-- TABLE OF CONTENTS -->
30
31# Table of Contents
32
33- [React Native Tools Preview](#react-native-tools-preview)
34- [Package extension locally](#package-extension-locally)
35- [About the extension](#about-the-extension)
36- [Getting started](#getting-started)
37- [React Native commands in the Command Palette](#react-native-commands-in-the-command-palette)
38- [Customize metro configuration](#customize-metro-configuration)
39- [Debugging React Native applications](#debugging-react-native-applications)
40 - [Hermes engine and direct debugging (Recommended)](#hermes-engine-and-direct-debugging-recommended)
41 - [Attach to Hermes application](#attach-to-hermes-application)
42 - [Android applications](#android-applications)
43 - [Android Hermes Debugging](#android-hermes-debugging)
44 - [Custom build for android apps](#custom-build-for-android-apps)
45 - [iOS applications](#ios-applications)
46 - [iOS Hermes debugging](#ios-hermes-debugging)
47 - [iOS devices](#ios-devices)
48 - [Custom scheme for iOS apps](#custom-scheme-for-ios-apps)
49 - [iOS direct debugging](#iOS-direct-debugging)
50 - [Expo applications](#expo-applications)
51 - [Debug on Expo Go](#debug-on-expo-go)
52 - [Debug on expo-dev-client](#debug-on-expo-dev-client)
53 - [Debug on Expo Web](#debug-on-expo-web)
54 - [Configuring Expo](#configuring-expo)
55 - [Expo Hermes](#expo-hermes)
56 - [EAS Build initialization](#eas-build-initialization)
57 - [Windows applications](#react-native-for-windows)
58 - [Windows Hermes debugging](#windows-hermes-debugging)
59 - [MacOS applications](#react-native-for-macos)
60 - [MacOS Hermes debugging](#macos-hermes-debugging)
61 - [Monorepo: debug out of React Native project directory](#monorepo-debug-out-of-react-native-project-directory)
62 - [Debugger configuration properties](#debugger-configuration-properties)
63 - [Re.Pack and Haul debugging](#repack-and-haul-debugging)
64 - [Remote JavaScript Debugging (Deprecated)](#remote-javascript-debugging-deprecated)
65- [Customization](#customization)
66 - [Sourcemaps](#sourcemaps)
67 - [Debug in vscode workspace](#debug-in-vscode-workspace)
68 - [Logging](#logging)
69 - [Build APK and generate bundle](#build-apk-and-generate-bundle)
70 - [Specifying custom arguments for `react-native run-*` command](#specifying-custom-arguments-for-react-native-run--command)
71 - [Setting up the React Native packager](#setting-up-the-react-native-packager)
72 - [Change project root](#change-project-root)
73 - [Configure an Android LogCat Monitor](#configure-an-android-logcat-monitor)
74 - [Configure dependencies versions for debugging Expo projects](#configure-dependencies-versions-for-debugging-expo-projects)
75 - [Configure custom key bindings for extension commands](#configure-custom-key-bindings-for-extension-commands)
76 - [Configure custom colors for extension output logs](#configure-custom-colors-for-extension-output-logs)
77 - [Set pnpm as package manager](#set-pnpm-as-package-manager)
78- [Element inspector (Deprecated)](#element-inspector-deprecated)
79- [Network Inspector](#network-inspector)
80- [Developing inside a Docker Container](#developing-inside-a-docker-container)
81- [Contributing](#contributing)
82- [Known Issues](#known-issues)
83
84# Getting started
85
86Before going any further make sure that you:
87
88- [have a working React Native environment](https://reactnative.dev/docs/environment-setup).
89- have the Android emulator available in your `PATH` or install iOS simulator in MacOS
90- are using [VS Code](https://code.visualstudio.com) and have [installed this extension from the Marketplace](https://marketplace.visualstudio.com/items?itemName=msjsdiag.vscode-react-native).
91- have your React Native project root folder open in VS Code.
92- have executed `React Native: Check development environment configuration` or `React Native: Run expo doctor`command to make sure that all necessary softwares are installed correctly.
93
94Please notice that the extension uses `.vscode/.react` directory at the project root to store intermediate files required for debugging. Although these files usually get removed after debug session ends, you may want to add this directory to your project's `.gitignore` file.
95
96# React Native commands in the Command Palette
97
98In the Command Palette, type `React Native` and choose a command.
99
100![React Native commands](resources/images/command-palette.png)
101
102The **Run Android** or **Run iOS** command triggers `react-native run-android` or `react-native run-ios` to starts your app for Android emulator or iOS simulator.
103
104The **Run Expo** command triggers `expo start` and starts your expo application.
105
106The **Packager** commands allow you to start/stop the [**Metro Bundler**](https://github.com/facebook/metro-bundler) (formerly React Packager).
107
108The full list of commands is:
109
110| Name | Command ID | Description |
111| --------------------------------------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
112| Launch Android Emulator | `reactNative.launchAndroidSimulator` | Prompts you to select the name of the available Android emulator and launch it. If only one emulator is installed in the system, it will be selected automatically |
113| Launch iOS Simulator | `reactNative.launchIOSSimulator` | Prompts you to select the available system version of the iOS simulator, then select the simulator name for the selected system and launch it. If only one simulator is installed in the system, it will be selected automatically |
114| Launch ExpoWeb | `reactNative.launchExpoWeb` | Check if the current project is an Expo project. If so, launch ExpoWeb. |
115| Run Android on Emulator | `reactNative.runAndroidSimulator` | Run an Android application on Emulator. Launch order: check target platform support, load run arguments, start Packager, run app on the selected emulator. Make sure the `emulator` utility is added to `PATH` |
116| Run Android on Device | `reactNative.runAndroidDevice` | Run an Android application on Device. Launch order: check target platform support, load run arguments, start Packager, run app in all connected devices |
117| Run iOS on Simulator | `reactNative.runIosSimulator` | Run an iOS application on Simulator. Launch order: load run arguments, check target platform support, start Packager, run app in only one connected emulator |
118| Run iOS on Device | `reactNative.runIosDevice` | Run an iOS application on Device. Launch order: load run arguments, check target platform support, start Packager, run app in only one connected device |
119| Run Expo | `reactNative.runExponent` | Run an Exponent application. Launch order: login to exponent, load run arguments, start Packager, run app |
120| Run Windows | `reactNative.runWindows` | Run a RNW application. Launch order: check target platform support, load run arguments, start Packager, run app |
121| Run MacOS | `reactNative.runMacOS` | Run a RNmacOS application. Launch order: check target platform support, load run arguments, start Packager, run app |
122| Start Packager | `reactNative.startPackager` | Start Packager in context project workspace folder |
123| Stop Packager | `reactNative.stopPackager` | Stop Packager |
124| Restart Packager | `reactNative.restartPackager` | Restart Packager and clear the Packager's cache |
125| Publish To Expo | `reactNative.publishToExpHost` | Publish to Exponent Host. Launch order: login to exponent, execute `Run Expo` command, then publish app to host |
126| Show Dev Menu | `reactNative.showDevMenu` | Show development menu for running application on iOS or Android device or emulator |
127| ReloadApp | `reactNative.reloadApp` | Reload an application |
128| Run Element Inspector | `reactNative.runInspector` | Load development tools for inspect application UI elements |
129| Stop Element Inspector | `reactNative.stopInspector` | Stop development tools for inspect application UI elements |
130| Run React Native LogCat Monitor | `reactNative.startLogCatMonitor` | Creates a LogCat Monitor for the chosen online Android device to see the device LogCat logs. Default filtering arguments: ["*:S", "ReactNative:V", "ReactNativeJS:V"]. [How to configure filtering.](#configure-an-Android-LogCat-Monitor) |
131| Stop React Native LogCat Monitor | `reactNative.stopLogCatMonitor` | Stops an existing LogCat Monitor and removes its output channel |
132| Run Network Inspector | `reactNative.startNetworkInspector` | Run [Network inspector](#network-inspector) |
133| Stop Network Inspector | `reactNative.stopNetworkInspector` | Stop [Network inspector](#network-inspector) |
134| Check development environment configuration | `reactNative.testDevEnvironment` | Checks your development environment for common problems |
135| Open the eas project in a web page | `reactNative.openEASProjectInWebPage` | Open EAS build in your EAS project portal |
136| Open react native upgrade helper in web page | `reactNative.openRNUpgradeHelper` | Open an official project upgrade tools in browser, support RN, RN for Windows, RN for MacOS |
137| Revert extension input in open package module | `reactNative.revertOpenModule` | Quickly revert some codes in Open Module which are changed by react-native-tools |
138| Run doctor | `reactNative.doctor` | Execute react-native doctor to check basic environment for react-native development |
139| Run expo doctor | `reactNative.ExpoDoctor` | Execute expo doctor to check basic environment for Expo development |
140| Expo prebuild | `reactNative.expoPrebuild` | Create the android and ios directories for running your React code |
141| Expo prebuild cleanup | `reactNative.expoPrebuildClean` | Clean directories generated by prebuild |
142| Reopen QR Code in Expo | `reactNative.reopenQRCode` | Reopen expo generated QR code in webview |
143| Enable Hermes | `reactNative.hermesEnable` | Use hermes as JavaScript engine for RN project |
144| Enable & Disable Expo Hermes | `reactNative.expoHermesEnable` | Use hermes or jsc as JavaScript engine for expo project |
145| Open expo upgrade helper in web page | `reactNative.openExpoUpgradeHelper` | Open expo upgrade helper in web browser |
146| Kill Port | `reactNative.killPort` | Kill the process running on a specific port |
147| Run EAS Build | `reactNative.runEasBuild` | Initialize EAS Build configuration by creating `eas.json` and `.eas/workflows/create-production-builds.yml` files if they don't exist |
148| Set React Native New Architecture | `reactNative.setNewArch` | Enable or disable the new architecture settings in RN projects |
149| Toggle Network View | `reactNative.toggleNetworkView` | Enable or disable vscode network view feature for web debugging |
150
151## Using commands in VS Code tasks
152
153To run React Native Tools commands via VS Code tasks, you can create a `.vscode/tasks.json` file in your project and add tasks configurations the following way:
154
155```json
156{
157 "version": "2.0.0",
158 "tasks": [
159 {
160 "label": "Run Android on Emulator",
161 "command": "${command:reactNative.runAndroidSimulator}",
162 "problemMatcher": []
163 }
164 ]
165}
166```
167
168# Customize metro configuration
169
170Metro is a JavaScript bundler for React Native and included in React Native package. Metro configuration can be customized in `metro.config.js`.
171
172# Debugging React Native applications
173
174To debug react-native application:
175
1761. Create `launch.json` file in `.vscode` folder.
1772. Click on `Add Configuration` button and choose `React Native` option.
1783. Select any scenario needed in dropdown list.
179
180![Add React Native debug configuration](resources/images/add-debug-configuration.gif)
181
1824. Choose the appropriate configuration in the Configuration dropdown, and then press F5 (or click _Green Arrow_ ![Configure-gear](resources/images/debug-icon.png) button) to start debugging your app in VS Code.
183
184![React Native launch targets](resources/images/debug-targets.png)
185
186Optional: The extension also allows to start debugging without creating the `launch.json` file in one of the following ways:
187
188- Using dynamic debugging configurations
189
190 To use dynamic debugging configurations you can click on the `Show all automatic debug configurations` string in the `Run and Debug` panel, then select `React Native` in the list of extensions and choose the appropriate configuration in the Configuration list to start debugging.
191
192 ![Run dynamic debugging configuration](resources/images/dynamic-debugging-configuration.gif)
193
194- Using `Debug` button in the Editor Title area menu
195
196 To start debugging you can click the Debug button in the Editor Title area in the upper right corner. You can also select the appropriate debugging scenario by clicking the dropdown button beside the Debug button and choosing the scenario.
197
198 ![Select and run debugging command](resources/images/debug-commands-button.png)
199
200The extension allows you to debug multiple devices and configurations, please read the following sections for more information for your particular use case.
201
202## Hermes engine and direct debugging (Recommended)
203
204React-native set Hermes as default engine. Please see [official documentation](https://reactnative.dev/blog/2022/07/08/hermes-as-the-default) to get details.
205
206The Hermes engine is an open source JavaScript engine created by Facebook to optimize building and running React Native applications. It improves app performance and decreases app size.
207
208Click [here](https://reactnative.dev/docs/hermes) to learn more about Hermes and how to enable it for your application.
209
210## Attach to Hermes application
211
212To attach to a running Hermes application use `Attach to Hermes application` launch configuration:
213
214```json
215{
216 "name": "Attach to Hermes application",
217 "cwd": "${workspaceFolder}",
218 "type": "reactnativedirect",
219 "request": "attach"
220}
221```
222
223## Android applications
224
225### Android Hermes debugging
226
227To debug while using Hermes engine use `Debug Android Hermes` launch configuration:
228
229```json
230{
231 "name": "Debug Android Hermes",
232 "cwd": "${workspaceFolder}",
233 "type": "reactnativedirect",
234 "request": "launch",
235 "platform": "android"
236}
237```
238
239### Custom build for Android apps
240
241If you want to use a custom `applicationIdSuffix` for your application to launch specific build, you can either pass it as part of the `runArguments` parameter arguments as shown below:
242
243```js
244"runArguments": ["--appIdSuffix", "customAppIdSuffix", ...]
245// or
246"runArguments": ["--appIdSuffix=customAppIdSuffix", ...]
247```
248
249## iOS applications
250
251### iOS Hermes debugging
252
253To debug your iOS Hermes application, you can use `Debug iOS Hermes` launch configuration to debug an iOS Hermes application:
254
255```json
256{
257 "name": "Debug iOS Hermes",
258 "cwd": "${workspaceFolder}",
259 "type": "reactnativedirect",
260 "request": "launch",
261 "platform": "ios"
262}
263```
264
265### iOS devices
266
267Debugging on an iOS device requires following manual steps:
268
269- Install [ios-deploy](https://github.com/ios-control/ios-deploy) `brew install ios-deploy`.
270- Install a valid iOS development certificate.
271- In your project's `launch.json` file set `target` to `device`. If you need to specify the exact device to run, you can set `target` to `<iOS device name/udid>`, or you can also use `runArguments` property to specify a particular device to run on in case multiple devices are connected (e.g. `"runArguments": [ "--device", "My iPhone" ]`)
272- Choose the **Debug iOS Hermes** option from the "Configuration" dropdown and press F5.
273
274### Custom scheme for iOS apps
275
276If you want to use a custom scheme for your application you can either pass it as part of the `runArguments` parameter arguments as shown below:
277
278```js
279"runArguments": ["--scheme", "customScheme", ...]
280// or
281"runArguments": ["--scheme=customScheme", ...]
282```
283
284Please be aware, specifying the scheme value as a part of the `runArguments` parameter arguments will override the `scheme` configuration parameter value, if it set.
285
286### iOS direct debugging
287
288The extension provides experimental support of iOS direct debugging. See more info here: [react-native-community/discussions-and-proposals#40](https://github.com/react-native-community/discussions-and-proposals/issues/40), [react-native-community/discussions-and-proposals#206](https://github.com/react-native-community/discussions-and-proposals/issues/206)
289
290For now the extension supports iOS direct debugging only on real iOS devices.
291
292Since this scenarios are using some 3rd party tools for the debugging process. Sometimes it may have limitation from upstream. We still recommend using **Hermes direct debugging** as a first choice.
293
294To be able to debug an iOS app directly, you need to install [ios-webkit-debug-proxy](https://github.com/google/ios-webkit-debug-proxy):
295
296- Install [HomeBrew](https://brew.sh) on your Mac.
297- Open a Terminal and run `brew install ideviceinstaller ios-webkit-debug-proxy`
298
299You can use the following debug scenarios to debug iOS apps directly:
300
301- React Native Direct: Debug Direct iOS - Experimental
302
303```json
304 "name": "Debug Direct iOS - Experimental",
305 "cwd": "${workspaceFolder}",
306 "type": "reactnativedirect",
307 "request": "launch",
308 "platform": "ios",
309 "port": 9221,
310 "target": "device"
311```
312
313- React Native Direct: Attach to the React Native iOS - Experimental
314
315```json
316 "name": "Attach to the React Native iOS - Experimental",
317 "cwd": "${workspaceFolder}",
318 "type": "reactnativedirect",
319 "request": "attach",
320 "platform": "ios",
321 "port": 9221
322```
323
324## Expo applications
325
326Extension also support [Expo](https://expo.dev/) application debugging scenarios.
327
328To create Expo application, please prepare your environment by following the [Expo CLI Quickstart instruction](https://reactnative.dev/docs/environment-setup).
329
330You can verify if the environment is ready to use by `React Native: Run Expo Doctor` in command palette.
331
332### Debug on Expo Go
333
334If you're using [Expo Go](https://expo.dev/expo-go), follow below steps to start debugging Expo application:
335
3361. Open your project in VS Code with this extension installed.
3372. Add below configure in `launch.json`.
338
339```json
340{
341 "name": "Debug Exponent Hermes",
342 "request": "launch",
343 "type": "reactnativedirect",
344 "cwd": "${workspaceFolder}",
345 "platform": "exponent",
346 "expoHostType": "local"
347}
348```
349
3503. Wait while some dependencies are configured - the extension will install [`Expo Development Library(xdl)`](https://www.npmjs.com/package/xdl) when this feature is used for the first time.
3514. Once the packager starts, the extension will open a separate tab with QR code and app link. You can open app in Expo Go and start debugging.
352 ![Expo QRCode](/resources/images/expo-qrcode.png)
353
354### Debug on expo-dev-client
355
356If you want to debug Expo app using [expo-dev-client](https://docs.expo.dev/development/getting-started/), follow below steps to start debugging Expo application:
357
3581. Open your project in VS Code with this extension installed.
3592. In project folder, install expo-dev-client for your app using `npx expo install expo-dev-client`.
3603. Create your app in development mode `eas build --profile development --platform all`, replace `--platform all` to `android` or `iOS` to build specific platform application(need development account for `iOS` platform).
3614. After build success, download your build and install application to your device or simulator.
3625. In project, using `npx expo start --dev-client` to start Metro and load application in device or simulator.
3636. Add `Attach to application` command `launch.json`, and start debugging.
364
365```json
366{
367 "name": "Attach to Hermes application",
368 "request": "attach",
369 "type": "reactnativedirect",
370 "cwd": "${workspaceFolder}"
371}
372```
373
374### Debug on Expo Web
375
376Expo support open application in browser, the expo web application is generated by [react-native-web](https://necolas.github.io/react-native-web/). It can help user open application without any Android emulator, iOS simulator or device. React-native-tools supports debugging Expo Web application in Chrome and Edge. Follow below steps to start Expo Web debugging:
377
3781. Open your project in VS Code with this extension installed.
3792. Check and install related package: `react-dom`, `react-native-web` and `@expo/webpack-config` (this package is deprecated from Expo 49) by `npx expo install` command.
3803. Add Expo Web debugging configure in `launch.json` and start debugging.
381
382```json
383{
384 "name": "Debug Expo Web",
385 "request": "launch",
386 "type": "reactnativedirect",
387 "cwd": "${workspaceFolder}",
388 "platform": "expoweb",
389 "browserTarget": "chrome",
390 "url": "http://localhost:8081"
391}
392```
393
394### Configuring Expo
395
396The extension supports running through Exponent not just the applications created with Expo but even pure React Native applications (in that case you need to add `expo` package to `node_modules` in order to make it work with Expo: `npm install expo --save-dev`. In either cases it uses `app.json` configuration file in the root of the project.)
397
398If you are running `Debug Exponent Hermes` configuration or any of palette commands like `Run in Exponent`, `Publish to Exponent` then this file will be created automatically if absent or updated with the following basic configuration section:
399
400```json
401{
402 "expo": {
403 "slug": "MyApp", // Project slug
404 "name": "MyApp", // Project name
405 "sdkVersion": "31.0.0", // Expo SDK version
406 "entryPoint": ".vscode\\exponentIndex.js" // Entrypoint for the project
407 },
408 "name": "MyApp" // Project name
409}
410```
411
412Full list of configuration parameters for `expo` section in `app.json` may be found on [official Expo documentation page](https://docs.expo.io/versions/latest/workflow/configuration).
413
414For running **pure React Native app**, the extension, creates and uses `.vscode/exponentIndex.js` which points to the app entrypoint (`index.js` or `index.android.js` or `index.ios.js`) file.
415
416If you want to change your app entrypoint (for example, from `index.js` to `index.android.js`), delete `.vscode/exponentIndex.js` and then restart your debugging session.
417
418**NOTE**: The extension caches the version of the exponent SDK used by your project. This is helpful since we don't want to install the SDK each time you run exponent. If you want the extension to update the SDK version based on your React Native version, just restart VS Code and if it is supported it should work. If it does not please open an issue.
419
420### Expo Hermes
421
422Expo using Hermes as default engine, you can switch engine on a specific platform using below configure.
423
424```json
425{
426 "expo": {
427 "jsEngine": "hermes",
428 "ios": {
429 "jsEngine": "jsc"
430 }
431 }
432}
433```
434
435**Note**: You maybe need to create developer account to run `eas build`. Any other issue or limitation, please see [expo hermes documentation](https://docs.expo.dev/guides/using-hermes/).
436
437### EAS Build initialization
438
439The **Run EAS Build** command (`reactNative.runEasBuild`) helps you quickly set up [Expo Application Services (EAS) Build](https://docs.expo.dev/build/introduction/) configuration in your Expo project.
440
441#### What it does
442
443When you run this command from the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P`), it will:
444
4451. Check if your project root directory is accessible
4462. Create an `eas.json` file (if it doesn't exist) with an empty configuration `{}`
4473. Create the `.eas/workflows/` directory structure
4484. Generate a `create-production-builds.yml` workflow file with the following content:
449
450```yaml
451name: Create Production Builds
452jobs:
453 build_android:
454 type: build # This job type creates a production build for Android
455 params:
456 platform: android
457 build_ios:
458 type: build # This job type creates a production build for iOS
459 params:
460 platform: ios
461```
462
463#### How to use
464
4651. Open your Expo project in VS Code
4662. Press `Ctrl+Shift+P` (Windows/Linux) or `Cmd+Shift+P` (macOS) to open the Command Palette
4673. Type "Run EAS Build" and select **React Native: Run EAS Build**
4684. The command will create the necessary files if they don't exist
469
470**Note**: The command is idempotent - it will not overwrite existing files. If the files already exist, the command will skip creation and display an appropriate message.
471
472#### Next steps after initialization
473
474After running this command, you should:
475
4761. **Configure `eas.json`**: Add your build profiles (e.g., `development`, `preview`, `production`). See [EAS Build Configuration](https://docs.expo.dev/build/eas-json/) for details.
477
4782. **Set up credentials**: Configure your iOS and Android signing credentials. Use `eas credentials` command or configure them in your EAS project.
479
4803. **Run your first build**:
481
482 ```bash
483 # For Android
484 npx eas build --platform android
485
486 # For iOS
487 npx eas build --platform ios
488
489 # For both platforms
490 npx eas build --platform all
491 ```
492
4934. **Customize workflows**: Edit `.eas/workflows/create-production-builds.yml` to add more complex build configurations, such as different build profiles, environment variables, or custom scripts.
494
4955. **Monitor builds**: Use `React Native: Open the eas project in a web page` command to view your build status in the EAS dashboard.
496
497#### Troubleshooting
498
499- **Permission errors**: Ensure VS Code has write permissions to your project directory
500- **Files already exist**: The command will skip file creation if they already exist - this is normal behavior
501- **Project not found**: Make sure you have opened a React Native/Expo project folder in VS Code
502
503For more information about EAS Build, visit the [official Expo documentation](https://docs.expo.dev/build/introduction/).
504
505## React Native for Windows
506
507Please make sure that your development environment is configured properly in accordance with [the official system requirements](https://microsoft.github.io/react-native-windows/docs/rnw-dependencies).
508
509And follow [the official guide](https://microsoft.github.io/react-native-windows/docs/hermes#hermes-on-windows) to enable Hermes engine for a Windows application.
510
511### Windows Hermes debugging
512
513To debug React Native for Windows applications, you can use below configure in `launch.json`:
514
515```json
516{
517 "name": "Debug Windows Hermes",
518 "cwd": "${workspaceFolder}",
519 "type": "reactnativedirect",
520 "request": "launch",
521 "platform": "windows"
522}
523```
524
525Also you can attach running application using `Attach to Hermes application` configuration to `.vscode/launch.json` in your project.
526
527## React Native for MacOS
528
529Please make sure that your development environment is configured properly in accordance with [the official system requirements](https://microsoft.github.io/react-native-windows/docs/rnm-dependencies).
530
531And follow [the official guide](https://microsoft.github.io/react-native-windows/docs/hermes#available-on-macos) to enable Hermes engine for a macOS application.
532
533### MacOS Hermes debugging
534
535To debug a macOS Hermes application you can use `Debug macOS Hermes` debugging scenario:
536
537```json
538{
539 "name": "Debug macOS Hermes",
540 "request": "launch",
541 "type": "reactnativedirect",
542 "cwd": "${workspaceFolder}",
543 "platform": "macos"
544}
545```
546
547Also you can attach running application using `Attach to Hermes application` configuration to `.vscode/launch.json` in your project.
548
549## Monorepo: debug out of React Native project directory
550
551If you're using monorepo like:
552
553```
554monorepo/
555├── apps/
556│ ├── app1/
557│ │ └── src/
558│ └── app2/
559│ └── src/
560├── packages/
561│ ├── ui/
562│ │ └── src/
563│ └── common/
564│ └── src/
565│ └── utils.ts
566└── package.json
567```
568
569When you import `utils.ts` in your project. Using
570
571```js
572import { commonFunction } from "../../packages/common/src/utils";
573```
574
575Will get error when start Metro:
576
577```
578error: bundling failed: Error: Unable to resolve module `../../packages/common/src/utils` from `src/App.js`
579```
580
581To debug your code in monorepo, please follow below steps:
582
5831. In `metro.config.js`, add extra module and watch folder.
584
585```js
586const extraNodeModules = {
587 common: path.resolve(__dirname + "/../packages/common/src"),
588};
589
590const watchFolders = [path.resolve(__dirname + "/../packages/common/src")];
591
592const config = {
593 resolver: {
594 extraNodeModules,
595 },
596 watchFolders,
597};
598```
599
6002. Import function in application.
601
602```js
603import { functionInUtils } from "common/utils";
604```
605
606or
607
608```js
609import { functionInUtils } from "../../packages/common/src/utils";
610```
611
6123. Set source map override config in `launch.json`. Example:
613
614```json
615/* Get source map url from vscode debug diagnostics tab */
616"sourceMapPathOverrides": {
617 "/[metro-watchFolders]/1/*": "/Monorepo-Project-Full-Path/*",
618}
619```
620
6214. Launch app and attach debugger
622
623## Debugger configuration properties
624
625The following is a list of all the configuration properties the debugger accepts in `launch.json`:
626
627| Name | Description | Type | Defaults |
628| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | --------------------------------------------- |
629| `cwd` | The path to the project root folder | `string` | `${workspaceFolder}` |
630| `sourceMaps` | Whether to use JavaScript source maps to map the generated bundled code back to its original sources | `boolean` | `true` |
631| `sourceMapPathOverrides` | A set of mappings for rewriting the locations of source files from what the source map says, to their locations on disk. See [Sourcemaps](#sourcemaps) for details | `object` | n/a |
632| `sourceMapRenames` | Whether to use the "names" mapping in sourcemaps. This requires requesting source content, which could slow debugging | `boolean` | `false` |
633| `enableDebug` | Whether to enable debug mode. If set to "false", an application will be launched without debugging | `boolean` | `true` |
634| `webkitRangeMin`, `webkitRangeMax` | Combines to specify the port range that you want the [ios-webkit-debug-proxy](https://github.com/google/ios-webkit-debug-proxy) to use to find the specific device described in the Direct iOS debug configuration | 9223, 9322 |
635| `trace` | Logging level in debugger process. May be useful for diagnostics. If set to "Trace" all debugger process logs will be available in `Debug Console` output window | `string` | `log` |
636| `address` | TCP/IP address of packager to attach to for debugging | `string` | `localhost` |
637| `port` | Port of packager to attach to for debugging | `string` | `8081` |
638| `remoteRoot` | The source root of the remote host | `string` | `null` |
639| `localRoot` | The local source root that corresponds to the 'remoteRoot' | `string` | `${workspaceFolder}` |
640| `skipFiles` | An array of file or folder names, or glob patterns, to skip when debugging | `array` | `[]` |
641| `debuggerWorkerUrlPath` | Path to the app debugger worker to override. For example, if debugger tries to attach to http://localhost:8081/debugger-ui/debuggerWorker.js and you get 404 error from packager output then you may want to change debuggerWorkerUrlPath to another value suitable for your packager (\"debugger-ui\" will be replaced with the value you provide) | `string` | `debugger-ui/` |
642| `platform` | The platform to target. Possible values: `android`, `ios`, `exponent`, `windows` | `string` | n/a |
643| `target` | Target to run on. Possible values: `simulator`, `device`, `<iOS target name/udid>`, [`<Android target id>`](https://github.com/react-native-community/cli/blob/master/docs/commands.md#--deviceid-string), `<Android emulator AVD name>`. If the value is `simulator` or `device` then the quick pick window will be expanded with the names of the available virtual or physical targets, then, in case there are more than one available target with specified type, the target value in `launch.json` will be changed to the name or id of the selected target. If you have only one target with specified type available, it will be selected automatically. If you're using Android emulator targets, please, make sure the `emulator` utility is added to `PATH` | `string` | `simulator` |
644| `logCatArguments` | Arguments to be used for LogCat (The LogCat output will appear on an Output Channel). It can be an array such as: `[":S", "ReactNative:V", "ReactNativeJS:V"]` | `array` | `["*:S", "ReactNative:V", "ReactNativeJS:V"]` |
645| `runArguments` | Run arguments to be passed to `react-native run-<platform>` command (override all other configuration params) | `array` | n/a |
646| `launchActivity` | The Android activity to be launched for debugging, e.g. it specifies [`--main-activity`](https://github.com/react-native-community/cli/blob/master/docs/commands.md#--main-activity-string) parameter in `react-native` run arguments | `string` | `MainActivity` |
647| `expoHostType` | The connection type to be used on Expo debugging to communicate with a device or an emulator. Possible values: <ul><li>`tunnel` - allows to deploy and debug an application by means of Expo cloud services</li><li>`lan` - allows to deploy and install an application via your LAN</li><li>`local` - allows to debug an application on an emulator or an Android device without network connection</li></ul> | `string` | `lan` |
648| `env` | Environment variables passed to the debugger and `react-native run-<platform>` command | `object` | `{}` |
649| `envFile` | Absolute path to a file containing environment variable definitions | `string` | `${workspaceFolder}/.env` |
650| `variant` | A variant to be passed to `react-native run-android`, e.g. use `devDebug` to specify `--variant=devDebug` | `string` | n/a |
651| `scheme` | A scheme name to be passed to `react-native run-ios`, e.g. `devDebug` to specify `--scheme=devDebug` | `string` | n/a |
652| `productName` | iOS bundle display name e.g. `AwesomeProject` value means that the extension will search for `AwesomeProject.app` bundle | `string` | n/a |
653| `jsDebugTrace` | Enable trace collection for depended extension `vscode-js-debug` | `boolean` | n/a |
654
655## Re.Pack and Haul debugging
656
657[Re.Pack](https://github.com/callstack/repack): A modern bundler for React Native applications, powered by Rspack and Webpack.
658
659[Haul](https://github.com/callstack/haul): A command line tool for developing React Native apps. Legacy tools, recommend using Re.Pack.
660
661Both Re.Pack and Haul can use `Attach` request to attach to a react-native based app and debug it.
662Add config in `launch.json` file as below, make sure adding `sourceMapPathOverrides` argument to update source map for your application webpack.
663
664For example:
665
666```json
667{
668 "name": "Attach to Hermes application",
669 "request": "attach",
670 "type": "reactnativedirect",
671 "cwd": "${workspaceFolder}",
672 "sourceMapPathOverrides": {
673 "webpack:///./~/*": "${workspaceRoot}/node_modules/*",
674 "webpack:///./*": "${workspaceRoot}/*",
675 "webpack:///*": "*"
676 }
677}
678```
679
680## Remote JavaScript Debugging (Deprecated)
681
682Remote JavaScript debugging is deprecated by react-native team from [0.73](https://reactnative.dev/docs/0.75/other-debugging-methods#remote-javascript-debugging-deprecated) and may be removed officially at any time.
683
684**We strongly recommend to use [Hermes engine and direct debugging](#hermes-engine-and-direct-debugging-recommended) in your application.**
685
686Below config showed classic debug mode in extension. With the version update of react-native, some features of Remote JavaScript Debugging may become unavailable, we will remove it from extension in the future if it's totally removed officially.
687
688```json
689{
690 "name": "Debug Android",
691 "request": "launch",
692 "type": "reactnative",
693 "cwd": "${workspaceFolder}",
694 "platform": "android"
695}
696```
697
698# Customization
699
700The extension can be further customized for other React Native scenarios. These are the most common:
701
702## Sourcemaps
703
704The debugger uses sourcemaps to let you debug with your original sources, but sometimes the sourcemaps aren't generated properly and overrides are needed. In the config we support `sourceMapPathOverrides`, a mapping of source paths from the sourcemap, to the locations of these sources on disk. Useful when the sourcemap isn't accurate or can't be fixed in the build process.
705
706The left hand side of the mapping is a pattern that can contain a wildcard, and will be tested against the `sourceRoot` + `sources` entry in the source map. If it matches, the source file will be resolved to the path on the right hand side, which should be an absolute path to the source file on disk.
707
708Below there are some examples of how sourcemaps could be resolved in different scenarios:
709
710```json
711// webRoot = /Users/me/project
712"sourceMapPathOverrides": {
713 "webpack:///./~/*": "${webRoot}/node_modules/*", // Example: "webpack:///./~/querystring/index.js" -> "/Users/me/project/node_modules/querystring/index.js"
714 "webpack:///./*": "${webRoot}/*", // Example: "webpack:///./src/app.js" -> "/Users/me/project/src/app.js",
715 "webpack:///*": "*", // Example: "webpack:///project/app.ts" -> "/project/app.ts"
716 "webpack:///src/*": "${webRoot}/*" // Example: "webpack:///src/app.js" -> "/Users/me/project/app.js"
717}
718```
719
720## Debug in vscode workspace
721
722Extension supports vscode multiple root workspace for development. If you have several react-native project in workspace, extension will show project selection list when react-native packager is starting. Also you can add settings in workspace to ignore specific project in selection list.
723
724- Open vscode command palette, select `Preferences: Open Workspace Settings (JSON)` to open workspace settings file.
725- Add below settings in the file:
726
727```json
728 "settings": {
729 "react-native.workspace.exclude": [
730 "ProjectFolderName1",
731 "ProjectFolderName2"
732 ]
733 }
734```
735
736- Since the folder selection list is handled by vscode rather than extension, we must set exclude folder when extension is not activated. If you add exclude folder after extension activating, you must re-activate you extension or reopen your vscode.
737
738## Logging
739
740The extension logging is divided by several output channels:
741
742- React Native - the main extension channel which collects outputs from React Native Packager and shows critical errors in the extension
743- These channels are spawned only when the specific launch scenario is executed:
744 - React Native: Run Android
745 - LogCat monitor(to get LogCat output from Android device, can be filtered by debug configuration settings)
746 - React Native: Run iOS
747 - React Native: Run macOS
748 - React Native: Run Windows
749 - React Native: Run exponent
750- Debug Console which is used to receive application logs and logs generated by the debug adapter (`console.log` and other `std` outputs from the app)
751- Extension debugger verbose logs (these logs are shown up only if the `trace: "verbose"` option is enabled in debug scenarios)
752 - React Native Chrome Proxy - shows what runs in and out to the debugger and application
753 - Debug Console becomes more informative and contains some debugging information from the debug adapter
754 - Global extension errors are controlled by VS Code and printed in VS Code Developer Tools
755
756There are also some global extension technical logs that might be exposed to the output. To see them set the following properties in your VS Code Settings:
757
758```json
759{
760 "react-native-tools": {
761 "logLevel": "Trace"
762 }
763}
764```
765
766`logLevel` can be `None` (no logs), `Error`, `Warning`, `Info`, `Debug`, `Trace` (all logs). Default is `Info`.
767
768## Build APK and generate bundle
769
770You can add VSCode tasks to build an `.apk` file and generate iOS/Android bundles.
771
772The following is an example of a `tasks.json` for `react-native init` projects.
773Place it in the `.vscode` folder in your project to use it:
774
775```json
776{
777 "version": "2.0.0",
778 "presentation": {
779 "reveal": "always",
780 "panel": "new"
781 },
782 "tasks": [
783 {
784 "label": "Build APK Debug",
785 "group": "build",
786 "type": "shell",
787 "windows": {
788 "command": "cd android; if($?) {./gradlew assembleDebug}"
789 },
790 "linux": {
791 "command": "cd android && ./gradlew assembleDebug"
792 }
793 },
794 {
795 "label": "Build APK Release",
796 "group": "build",
797 "type": "shell",
798 "windows": {
799 "command": "cd android; if($?) {./gradlew assembleRelease}"
800 },
801 "linux": {
802 "command": "cd android && ./gradlew assembleRelease"
803 }
804 },
805 {
806 "label": "Generate Android Bundle",
807 "group": "build",
808 "type": "shell",
809 "command": "npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/main.jsbundle"
810 },
811 {
812 "label": "Generate iOS Bundle",
813 "group": "build",
814 "type": "shell",
815 "command": "npx react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ios/main.jsbundle"
816 }
817 ]
818}
819```
820
821To learn more about `tasks` in VSCode read [the official documentation](https://code.visualstudio.com/docs/editor/tasks).
822
823Visit [generating Signed APK](https://reactnative.dev/docs/signed-apk-android) to learn more about this subject.
824
825## Specifying custom arguments for `react-native run-*` command
826
827Using custom run arguments for `react-native run-<platform>`:
828**NOTE:** This overrides all other configuration parameters.
829
830```json
831{
832 "react-native.android.runArguments.simulator": [
833 "--appFolder",
834 "/Users/test/AwesomeProject/android/app",
835 "--deviceId",
836 "emulator-5555"
837 ],
838 "react-native.ios.runArguments.device": [
839 "--project-path",
840 "ios",
841 "--device",
842 "Max's iPhone"
843 ]
844}
845```
846
847**NOTE:** You can get the list of installed simulator devices by:
848
849iOS devices (macOS only):
850
851```
852xcrun simctl list --json devices
853```
854
855Android devices:
856
857```
858adb devices
859```
860
861**NOTE:** If you want to run the application on an iOS device, make sure you have `ios-deploy` installed globally.
862
863`brew install ios-deploy`
864
865## Setting up the React Native packager
866
867To use a custom port for the `react-native` packager:
868
869```json
870{
871 "react-native": {
872 "packager": {
873 "port": portNumber
874 }
875 }
876}
877```
878
879If you change this port, then for iOS device and simulator scenarios you will have to modify the native code files. [Instructions here](https://childofcode.com/react-native-0-63-running-on-device-by-other-port-solution/).
880
881If you use Android, you need to change the debug server by:
882
8831. `CTRL+M`(`CMD+M`) in the emulator
8842. Go to `Dev Settings`
8853. Debug server host for device => enter `localhost:<yourPortNumber>`.
8864. Reload application (press `R` twice)
8875. (Hermes only) Hermes engine listens port 8081 for debugging by default, to change it you might need to modify your [`metro.config.js` file adding `"port": portNumber` argument in there to the server settings](https://facebook.github.io/metro/docs/configuration/#port).
888
889```js
890// Example of metro.config.js (<= 0.72.0)
891module.exports = {
892 server: {
893 port: 9091,
894 },
895};
896```
897
898OR
899
900```js
901// Example of metro.config.js (0.72.0)
902const config = {
903 server: {
904 port: 9091,
905 },
906};
907```
908
909<details>
910<summary>Port setup instruction</summary>
911
912![image](resources/images/select-dev-menu.png)
913
914![image](resources/images/dev-menu-setup-custom-host.png)
915
916![image](resources/images/custom-host-and-port.png)
917
918</details>
919
920**NOTE:** Some aspects of React Native hard-code the port to the default as specified in [this issue](https://github.com/facebook/react-native/issues/9145).
921
922### Custom environment variables
923
924Extension supports passing custom environment variables to the React Native Packager process context. To add custom variables you can create `.env` file in the root folder of your project and add needed environment variables in the following format:
925
926```
927
928Variable1_name=Variable1_value
929Variable2_name=Variable2_value
930
931```
932
933Variables that are declared in this `.env` file can override the original environment variables from `process.env` of the Packager process.
934
935It is possible to transfer environment variables (via `env` and `envFile` arguments in `launch.json`) from the `launch` or `attach` debug scenarios to the Packager. If these variables are defined, then they will be used, otherwise the `.env` file is used.
936
937## Change project root
938
939To specify a subfolder in which the react-native project is located, set `react-native-tools.projectRoot`. You can use either an absolute or relative path in your VS Code Settings:
940
941```json
942{
943 "react-native-tools": {
944 "projectRoot": "./your/react-native/project"
945 }
946}
947```
948
949## Configure an Android LogCat Monitor
950
951There are two ways to filter your LogCat Monitor output depending on how LogCat Monitor was launched:
952
9531. Since LogCat Monitor is launched for all Android launch scenarios by default, you can add `logCatArguments` to your debug scenario in `launch.json` file like in the following example:
954
955```json
956{
957 "name": "Debug Android Hermes",
958 "cwd": "${workspaceFolder}",
959 "type": "reactnativedirect",
960 "request": "launch",
961 "platform": "android",
962 "logCatArguments": ["ReactNativeJS:V"]
963}
964```
965
9662. If you want to launch LogCat Monitor from the Command Palette command `React Native: Run React Native LogCat Monitor` with filtering options set `react-native.android.logCatArguments` settings in your `settings.json`:
967
968```json
969{
970 "react-native.android.logCatArguments": [
971 "*:S",
972 "ReactNative:V",
973 "ReactNativeJS:V"
974 ]
975}
976```
977
978To have better understanding on how LogCat filtering works take into account that the extension launches LogCat with flag `-s` and then adds user-provided filters as arguments. Please see the [official instruction on how does LogCat filtering works](https://developer.android.com/studio/command-line/logcat#filteringOutput).
979
980## Configure dependencies versions for debugging Expo projects
981
982To debug Expo applications the extension requires additional dependencies, such as `xdl` and `@expo/metro-config`. These packages are installed automatically on the first start of the Expo debugging scenario. You can configure the dependencies versions by adding the `react-native.expo.dependencies` parameter, which contains packages names and appropriate versions, to the `settings.json` file:
983
984```json
985{
986 "react-native.expo.dependencies": {
987 "xdl": "59.2.0",
988 "@expo/metro-config": "0.2.0",
989 "@expo/ngrok": "^4.1.0"
990 }
991}
992```
993
994To enable new versions of the dependencies, it's required to restart VS Code editor. After that the extension will download the new versions of the packages on the next Expo debugging starting.
995
996## Configure custom key bindings for extension commands
997
998The extension provides context variables for the following features:
999|Context variable|Feature|
1000|---|---|
1001|`isRNPackagerRunning` - true if the packager is running|Metro packager|
1002|`isRNTNetworkInspectorRunning` - true if the Network inspector is running|Network inspector|
1003
1004Using these context variables you can assign the same keyboard combination for some pair commands for more convenient use. For example, you can configure the same key bindings for `Start Packager` and `Stop Packager` commands using `when` clauses, as shown below:
1005![image](resources/images/custom-keybindings.png)
1006
1007## Configure custom colors for extension output logs
1008
1009The extension provides custom TextMate tokens, with the help of which it is now possible to customize the colors of the logs in output channels:
1010|Scope|Description|
1011|---|---|
1012|`rnt.output.string`|Single and double quoted strings|
1013|`rnt.output.url`|Links, email and ip address, filepaths|
1014|`rnt.output.timestamp`|Date and time|
1015|`rnt.output.numeric`|Constant decimal numbers|
1016|`rnt.output.process`|Logs of processes such as npm, bundle, and other build tasks|
1017|`rnt.output.error`|Errors, exceptions, fails and stack for them|
1018|`rnt.output.warn`|Warning logs|
1019|`rnt.output.info`|Info logs|
1020|`rnt.output.debug`|Debug logs|
1021|`rnt.output.verbose`|Verbose logs|
1022|`rnt.output.constant`|Such values as `true`, `false`, `null`, `undefined`, `NaN`|
1023|`rnt.output.success`|Logs indicating successful completion of the process, such as `BUILD SUCCESSFUL` and others|
1024
1025Now you can customize React Native Tools output logs with `editor.tokenColorCustomizations` parameter in `settings.json` this way:
1026
1027```json
1028"editor.tokenColorCustomizations": {
1029 "textMateRules": [
1030 {
1031 "settings": {
1032 "foreground": "#c57ca0",
1033 "fontStyle": "bold",
1034 },
1035 "scope": "rnt.output.string"
1036 }
1037 ]
1038}
1039```
1040
1041## Set pnpm as package manager
1042
1043If you want to use pnpm as your package manager, please set `react-native-tools.setPackageManager` settings in your `settings.json`:
1044
1045```json
1046{
1047 "react-native-tools.setPackageManager": "pnpm"
1048}
1049```
1050
1051# Element inspector (Deprecated)
1052
1053In the extension you can run React DevTools Element inspector to inspect the DOM-tree of your application.
1054It's required to install the [`react-devtools`](https://www.npmjs.com/package/react-devtools) package globally to run React DevTools from the extension.
1055
1056**Note: react-devtools is deprecated from 0.76.**
1057
1058```
1059npm install -g react-devtools
1060```
1061
1062### Integration with React Native Inspector
1063
1064You can open the in-app developer menu and choose "Show Element Inspector". It will bring up an overlay that lets you tap on any UI element and see information about it:
1065
1066![Element inspector usage](resources/images/element-inspector-usage.gif)
1067
1068Using the `Run Element Inspector` Command Palette command you can launch React DevTools in the extension. Inspector will enter a special collapsed mode, and use the DevTools as primary UI. In this mode, clicking on something in the emulator will bring up the relevant components in the DevTools:
1069
1070![Element inspector usage](resources/images/element-inspector-with-ui.png)
1071
1072# Network Inspector
1073
1074The extension provides `Network inspector` feature to inspect outgoing network traffic in your apps. You can browse all requests being made and their responses in VS Code DevTools console.
1075
1076![image](resources/images/network-inspector.png)
1077
1078### Network inspector requirements
1079
1080Before using the Network inspector, please make sure that your system meets the following requirements:
1081
1082- `OpenSSL` utility is installed and added to PATH. You can install `OpenSSL` the following way:
1083 - Windows: `choco install openssl`
1084 - macOS: `brew install openssl`
1085 - Linux: `sudo apt-get install openssl`
1086- (macOS only) [`idb`](https://fbidb.io/docs/installation/) utility is installed. It's required to interact with iOS physical devices
1087
1088The Network inspector uses functional of the Flipper plugin integrated to React Native apps. Please make sure that it's enabled in your application. You can use [this guide](https://fbflipper.com/docs/getting-started/react-native/) to integrate Flipper into your projects.
1089
1090### Network inspector usage
1091
1092- To run the Network inspector you can use `Run Network Inspector` Command Palette command</br>
1093 When the Network inspector detects a React Native application and connects to it, VS Code DevTools window will be opened automatically. But you can also open it manually, by opening `Help` menu and clicking `Toggle Developer Tools` option. After that you just need to open `Console` tab in DevTools, where network requests will be printed.
1094- To stop the Network inspector you can use `Stop Network Inspector` Command Palette command
1095
1096For now the Network inspector doesn't support Expo applications.
1097
1098### Network inspector logs theme
1099
1100The extension provides “Dark” and “Light” color themes for Network Inspector logs. You can configure the theme in the extension configuration in your VS Code Settings.
1101
1102```json
1103{
1104 "react-native-tools.networkInspector.consoleLogsColorTheme": "Dark"
1105}
1106```
1107
1108# Developing inside a Docker Container
1109
1110The extension supports [VS Code Remote Development](https://code.visualstudio.com/docs/remote/remote-overview) features on Linux. Please follow the [VS Code official documentation](https://code.visualstudio.com/docs/devcontainers/containers) to setup your environment and install related extensions([Remote Development](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) is recommended) to use a remote development approach.
1111
1112You can use [official React Native Docker image](https://hub.docker.com/r/reactnativecommunity/react-native-android) provided by the [react-native-community](https://github.com/react-native-community/docker-android).
1113
1114Here are the steps to run React Native debugging inside a Docker Container on a real Android device:
1115
11161. In the local react-native project, add `Dev Container` configure folder and files:
1117 ```
1118 .devcontainer
1119 -devcontainer.json
1120 -Dockerfile
1121 ```
11222. Create Dockerfile extending [reactnativecommunity/react-native-android image](https://hub.docker.com/r/reactnativecommunity/react-native-android). For example you can use the following Dockerfile:
1123
1124 ```
1125 FROM reactnativecommunity/react-native-android:latest
1126
1127 RUN npm install -g expo-cli react-native-cli
1128 ```
1129
11303. Configure your `devcontainer.json` file as needed. Below is a sample configuration:
1131
1132 ```json
1133 {
1134 "name": "React Native Android Container",
1135
1136 // Sets the run context to one level up instead of the .devcontainer folder.
1137 "context": "..",
1138
1139 // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
1140 "dockerFile": "Dockerfile",
1141
1142 // The optional 'runArgs' property can be used to specify additional runtime arguments.
1143 "runArgs": [
1144 "--privileged", // give all capabilities to a container, in other words, the container can then do almost everything that the host can do
1145 "--net",
1146 "host", // forwarding all host machine ports
1147 "-v",
1148 "/dev/bus/usb:/dev/bus/usb" // mount connected USB devices to a container
1149 ],
1150 "customizations": {
1151 "vscode": {
1152 "settings": {
1153 // This will ignore your local shell user setting for Linux since shells like zsh are typically
1154 // not in base container images. You can also update this to an specific shell to ensure VS Code
1155 // uses the right one for terminals and tasks. For example, /bin/bash (or /bin/ash for Alpine).
1156 "terminal.integrated.shell.linux": null
1157 },
1158 // Add the IDs of extensions you want installed when the container is created in the array below.
1159 "extensions": ["msjsdiag.vscode-react-native"]
1160 }
1161 }
1162 }
1163 ```
1164
11654. Open Command Palette and run the following command `Dev Containers: Open Folder in Container` to reopen your project in a container
11665. Connect your device via USB and start debugging the same way as on local machine.
1167
1168Currently the above scenario doesn't work on macOS and Windows. Docker Container implementation on these OS uses Virtual Machine tools which may have problems with USB forwarding for mobile devices.
1169
1170# Contributing
1171
1172Please see our [contributing guide](CONTRIBUTING.md) for more information.
1173
1174# Known Issues
1175
1176Here is the list of common known issues you may experience while using the extension:
1177
1178| Issue | Description |
1179| ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1180| Debugger doesn't stop at breakpoints | Breakpoints require sourcemaps to be correctly configured. If you are using TypeScript, then make sure to follow the `Getting started` section for how to ensure sourcemaps are correctly set up. Also, similar issues may occur on React Native version `0.58.*` in some special cases (see [#928](https://github.com/microsoft/vscode-react-native/issues/928), [#907](https://github.com/microsoft/vscode-react-native/issues/907)), bumping dependencies versions of `react` and `react-native` package to the more recent ones should resolve these. If you are on Linux, make sure that the project folder which is opened is not a symbolic link to the real folder, that might cause problems with sourcemaps (see [#1456](https://github.com/microsoft/vscode-react-native/issues/1456)) |
1181| 'adb: command not found' | If you receive an error `adb: command not found`, you need to update your system Path to include the location of your _ADB_ executable.The _ADB_ executable file is located in a subdirectory along with your other Android SDK files. |
1182| Can't communicate with socket pipe | (Linux only) If you have two workspaces open that only differ in casing, the extension will fail to communicate effectively. |
1183| "Add configuration" button doesn't work when trying to add debug configuration to `launch.json` | You have to add some json configuration to `launch.json` manually. Please, see ([#985](https://github.com/microsoft/vscode-react-native/issues/985)). |
1184| Error `None of these files exist: * .vscode/exponentIndex` appears when running React Native apps via Expo | On some project configurations (mostly on macOS) there could be problems with running RN app via Expo for the first time. You can resolve this by explicitly adding `module.exports.watchFolders = ['.vscode'];` to your Metro config. This will help Metro bundler to find the custom entry point generated by the extension needed to work with Expo. For details you can see the issue ([#1327](https://github.com/microsoft/vscode-react-native/issues/1327)). |
1185| High CPU load notification while starting debugging Expo app | When you start debugging the Expo application you may receive the notification `"The extension 'React Native Tools' took a very long time to complete its last operation and it has prevented other extensions from running"`. The issue occurs because of importing the `xdl` package, which extension uses for debugging Expo applications. The `xdl` package has the large size and some peculiarities of its structure, so it may cause high CPU load. |
1186
1187[Known-Issues](https://github.com/microsoft/vscode-react-native/issues?q=is%3Aissue+label%3Aknown-issues) provides a complete list of active and resolved issues.
1188
1189# Telemetry reporting
1190
1191VS Code React Native extension collects usage data and sends it to Microsoft to help improve our products and services. Read our [privacy statement](https://www.visualstudio.com/en-us/dn948229) to learn more.
1192
1193If you don’t wish to send usage data to Microsoft:
1194create and add `VSCodeTelemetrySettings.json` file at `~/.vscode-react-native` and add `optIn:false`. Or add `react-native-tools.telemetry.optIn: false` in `~/.vscode/settings.json` file.
1195
1196# Code of conduct
1197
1198This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
1199