<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Webstorm on Haseeb Majid</title>
    <link>https://haseebmajid.dev/tags/webstorm/</link>
    <description>Recent content in Webstorm on Haseeb Majid</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Fri, 07 Sep 2018 00:00:00 +0000</lastBuildDate><atom:link href="https://haseebmajid.dev/tags/webstorm/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Debugging React Native apps in WebStorm and Visual Studio Code</title>
      <link>https://haseebmajid.dev/posts/2018-09-07-debugging-react-native-apps-in-webstorm-and-visual-studio-code/</link>
      <pubDate>Fri, 07 Sep 2018 00:00:00 +0000</pubDate>
      
      <guid>https://haseebmajid.dev/posts/2018-09-07-debugging-react-native-apps-in-webstorm-and-visual-studio-code/</guid>
      <description>&lt;p&gt;Visual Studio Code and WebStorm are two popular editors for developing React Native/Expo apps. These editors have lots
of useful features, such as syntax highlighting, git integration and auto completion. However working out to debug
Expo apps can be a bit confusing.&lt;/p&gt;
&lt;p&gt;One of the main advantages of working in an editor/IDE (let us be honest Visual Studio Code is pretty close to an IDE)
is being able to use a debugger (and breakpoints) to go through your code line by line and see which part of your code
is not running as expected. Debuggers can be a powerful tool when trying to remove bugs from your software, being able
to stop your code at any point and check the state, analyse variables etc.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>Visual Studio Code and WebStorm are two popular editors for developing React Native/Expo apps. These editors have lots
of useful features, such as syntax highlighting, git integration and auto completion. However working out to debug
Expo apps can be a bit confusing.</p>
<p>One of the main advantages of working in an editor/IDE (let us be honest Visual Studio Code is pretty close to an IDE)
is being able to use a debugger (and breakpoints) to go through your code line by line and see which part of your code
is not running as expected. Debuggers can be a powerful tool when trying to remove bugs from your software, being able
to stop your code at any point and check the state, analyse variables etc.</p>
<p>You can actually debug, with breakpoints and all those other fancy features, your Expo apps in both IDEs
(WebStorm and Visual Studio Code). I will be running my app in a <a href="https://genymotion.com/">Genymotion Android emulator</a>.
Also please note there are likely several ways to debug your React Native/Expo app , I’m simply showing you the way
I was able to get my debugger running.</p>
<p>
  <img
    loading="lazy"
    src="https://media.giphy.com/media/ThOHTmBZlHOQ8/giphy.gif"
    alt="Debugging"
    
  /></p>
<h2 id="prerequisite">Prerequisite</h2>
<ul>
<li>Have an <a href="https://expo.io/learn">Expo</a> app</li>
<li>Turn on &ldquo;Debug JS Remotely&rdquo; on your android device, as shown in Figure 1. In Genymotion you can open the &ldquo;Developer Menu&rdquo; menu by pressing CTRL + M. More information <a href="http://facebook.github.io/react-native/docs/debugging">here</a></li>
<li>Connect to your Android device using ADB</li>
</ul>
<p><code>adb connect 192.168.101.1 # Replace with your Device IP</code></p>
<p><img
        loading="lazy"
        src="/posts/2018-09-07-debugging-react-native-apps-in-webstorm-and-visual-studio-code/images/android-emulator.png"
        type=""
        alt="Figure 1: Turn on &ldquo;Debug JS Remotely&rdquo; on an Android device"
        
      /></p>
<h2 id="webstrom">WebStrom</h2>
<ul>
<li>Install and turn on CORS plugin in Chrome, make sure it&rsquo;s the same chrome browser you use in your configuration. (NOTE make sure your aware of the security implication on using CORS, switch the plugin off when your not using it).</li>
<li>Open WebStorm and your Expo project</li>
<li>Add the following lines of code to your <em>package.json</em> file</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="s2">&#34;scripts&#34;</span><span class="err">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;start&#34;</span><span class="p">:</span> <span class="s2">&#34;exp start&#34;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><ul>
<li>Create a new configuration of type &ldquo;React Native&rdquo; with the settings shown in Figure 3. Remember to add a new the &ldquo;Before launch&rdquo; configuration and select configuration type &ldquo;React Native Bundler&rdquo;</li>
<li>Run the configuration you just created in debug mode (SHIFT + F9)</li>
<li>Open a terminal window and run</li>
</ul>
<p><code>exp android</code></p>
<p><img
        loading="lazy"
        src="/posts/2018-09-07-debugging-react-native-apps-in-webstorm-and-visual-studio-code/images/webstorm-configuration.png"
        type=""
        alt="Figure 2: Run/Debug Configuration settings."
        
      /></p>
<p><img
        loading="lazy"
        src="/posts/2018-09-07-debugging-react-native-apps-in-webstorm-and-visual-studio-code/images/webstorm.gif"
        type=""
        alt="Figure 3: WebStorm; Starting the Debugger"
        
      /></p>
<h2 id="visual-studio-code">Visual Studio Code</h2>
<ul>
<li>Open Visual Studio Code and your Expo project</li>
<li>Create a new file in your vscode folder called <code>settings.json</code> and add the following</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="nt">&#34;react-native&#34;</span><span class="p">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;packager&#34;</span><span class="p">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">      <span class="nt">&#34;port&#34;</span><span class="p">:</span> <span class="mi">19001</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">  <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><ul>
<li>Go to &ldquo;Debug&rdquo; window (CTRL + SHIFT + D)</li>
<li>When prompted for environment choose &ldquo;React Native&rdquo;, it should give an <code>launch.json</code> file like this, make sure it contains the following:</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="err">[</span>
</span></span><span class="line"><span class="cl">        <span class="err">{</span>
</span></span><span class="line"><span class="cl">            <span class="nt">&#34;name&#34;</span><span class="p">:</span> <span class="s2">&#34;Attach to packager&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="nt">&#34;program&#34;</span><span class="p">:</span> <span class="s2">&#34;${workspaceRoot}/.vscode/launchReactNative.js&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="nt">&#34;type&#34;</span><span class="p">:</span> <span class="s2">&#34;reactnative&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="nt">&#34;request&#34;</span><span class="p">:</span> <span class="s2">&#34;attach&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="nt">&#34;sourceMaps&#34;</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="nt">&#34;outDir&#34;</span><span class="p">:</span> <span class="s2">&#34;${workspaceRoot}/.vscode/.react&#34;</span>
</span></span><span class="line"><span class="cl">        <span class="p">}</span><span class="err">,</span>
</span></span><span class="line"><span class="cl">    <span class="err">]</span>
</span></span><span class="line"><span class="cl"><span class="err">}</span>
</span></span></code></pre></div><ul>
<li>Open the integrated terminal (CTRL + `) and run</li>
</ul>
<p><code>exp start</code></p>
<ul>
<li>On top of the Debug menu should say &ldquo;Debug Android&rdquo; change this to &ldquo;Attach to packager&rdquo; and press &ldquo;Start Debugging&rdquo;</li>
<li>Open another terminal and run</li>
</ul>
<p><code>exp android</code></p>
<ul>
<li>Swap to &ldquo;Debug Console&rdquo; tab to see the debugger</li>
</ul>
<p><img
        loading="lazy"
        src="/posts/2018-09-07-debugging-react-native-apps-in-webstorm-and-visual-studio-code/images/visual-studio-code.gif"
        type=""
        alt="Figure 4: Visual Studio Code; Starting the Debugger."
        
      /></p>
<h2 id="appendix">Appendix</h2>
<ul>
<li>GIFs created with <a href="https://www.screentogif.com/">screentogif</a></li>
<li><a href="https://medium.com/r/?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0_MnXPD55-E">&ldquo;Debugging create-react-native-app with VSCode&rdquo;</a></li>
<li><a href="https://blog.jetbrains.com/webstorm/2018/02/webstorm-2018-1-eap-181-3263/">&ldquo;WebStorm 2018.1 EAP, 181.3263.21: improvements for React Native, extract Vue component&rdquo;</a></li>
<li>Icon made by <a href="https://www.flaticon.com/authors/monkik">Monik</a> from <a href="https://www.flaticon.com/">FlatIcon</a>and is licensed by <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons 3.0</a></li>
</ul>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
