<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Samuel Joseph</title>
    <description>The latest articles on Forem by Samuel Joseph (@sammytdev).</description>
    <link>https://forem.com/sammytdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3414745%2F836ce855-b315-409a-b7f8-7117ff0a2501.jpg</url>
      <title>Forem: Samuel Joseph</title>
      <link>https://forem.com/sammytdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sammytdev"/>
    <language>en</language>
    <item>
      <title>🚨 [48 Hours Lost] NativeWind + Expo Router = "Couldn't find a navigation context" Nightmare</title>
      <dc:creator>Samuel Joseph</dc:creator>
      <pubDate>Tue, 05 Aug 2025 13:20:51 +0000</pubDate>
      <link>https://forem.com/sammytdev/48-hours-lost-nativewind-expo-router-couldnt-find-a-navigation-context-nightmare-3opp</link>
      <guid>https://forem.com/sammytdev/48-hours-lost-nativewind-expo-router-couldnt-find-a-navigation-context-nightmare-3opp</guid>
      <description>&lt;p&gt;I just spent nearly &lt;strong&gt;48 hours debugging&lt;/strong&gt; an error in my Expo Router app that had nothing to do with what the error said.&lt;br&gt;
If you’re using &lt;strong&gt;NativeWind + React Navigation + Expo Router&lt;/strong&gt; — this post is for you. Save your time and sanity.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔥 The Error
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Couldn't find a navigation context."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're here, you’ve probably seen this and thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Ah, I must’ve forgotten to wrap something with &lt;code&gt;NavigationContainer&lt;/code&gt;."&lt;br&gt;
"Maybe the layout is off."&lt;br&gt;
"Is React Navigation broken?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Nope.&lt;/strong&gt; Everything was wired up correctly.&lt;/p&gt;

&lt;p&gt;But navigation still refused to work.&lt;br&gt;
Until I discovered that... &lt;strong&gt;NativeWind&lt;/strong&gt; was silently breaking everything.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 The Real Culprit: CSS Interop Race Condition
&lt;/h2&gt;

&lt;p&gt;Turns out, &lt;strong&gt;certain NativeWind class names&lt;/strong&gt; trigger runtime CSS parsing at render time.&lt;br&gt;
And if you’re using &lt;strong&gt;Expo Router&lt;/strong&gt;, this creates a subtle race condition:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React Navigation's context hasn't fully initialized yet.&lt;/li&gt;
&lt;li&gt;NativeWind starts processing your &lt;code&gt;className&lt;/code&gt; string.&lt;/li&gt;
&lt;li&gt;React components try to access the navigation context.&lt;/li&gt;
&lt;li&gt;Boom. ❌&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⚠️ Problematic NativeWind Classes
&lt;/h2&gt;

&lt;p&gt;Here are some of the class names that caused issues in my case:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;shadow-*&lt;/code&gt; → e.g. &lt;code&gt;shadow-sm&lt;/code&gt;, &lt;code&gt;shadow-md&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;opacity-*&lt;/code&gt; → e.g. &lt;code&gt;opacity-50&lt;/code&gt;, &lt;code&gt;opacity-70&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bg-color/opacity&lt;/code&gt; → e.g. &lt;code&gt;bg-white/15&lt;/code&gt;, &lt;code&gt;bg-black/30&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;text-color/opacity&lt;/code&gt; → e.g. &lt;code&gt;text-white/80&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They work fine in isolation.&lt;br&gt;
But in an &lt;strong&gt;Expo Router layout&lt;/strong&gt;, just one of these can trigger the bug.&lt;/p&gt;




&lt;h2&gt;
  
  
  💥 The Symptom
&lt;/h2&gt;

&lt;p&gt;If you're hitting any of these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;"Couldn't find a navigation context"&lt;/code&gt; errors randomly&lt;/li&gt;
&lt;li&gt;App works one minute and crashes the next&lt;/li&gt;
&lt;li&gt;Stack traces point to NavigationContainer setup&lt;/li&gt;
&lt;li&gt;Nothing makes sense anymore&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check your styles.&lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ The Fix: Use Inline Styles
&lt;/h2&gt;

&lt;p&gt;Replace the problematic class names with direct &lt;code&gt;style&lt;/code&gt; props.&lt;/p&gt;

&lt;h3&gt;
  
  
  ❌ Before:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;TouchableOpacity&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"bg-white/15 shadow-sm opacity-50"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ✅ After:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;TouchableOpacity&lt;/span&gt; 
  &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rgba(255, 255, 255, 0.15)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;shadowOffset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;shadowOpacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;shadowRadius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This completely solved the issue in my project.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Tech Stack
&lt;/h2&gt;

&lt;p&gt;This bug showed up in this combo:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Expo Router v5+&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NativeWind v4+&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;React Navigation v6+&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;React Native (latest)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧵 Why This Matters
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;error message is misleading&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;It’s &lt;strong&gt;timing-dependent&lt;/strong&gt; — the app may break or work based on device speed or render cycles&lt;/li&gt;
&lt;li&gt;You waste hours debugging the wrong thing&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ✅ What I Did
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Stripped it down to a &lt;strong&gt;minimal reproducible repo&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Posted the issue to &lt;a href="https://github.com/marklawlor/nativewind" rel="noopener noreferrer"&gt;NativeWind GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Writing this article to save &lt;strong&gt;you&lt;/strong&gt; from going through it too&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;I love NativeWind.&lt;br&gt;
I love Expo Router.&lt;br&gt;
But the two don’t always play nice — and when they don’t, it can really mess with your head.&lt;/p&gt;

&lt;p&gt;If you hit weird nav context issues in your app:&lt;br&gt;
✅ Check your layout&lt;br&gt;
✅ Then check your NativeWind &lt;code&gt;className&lt;/code&gt;&lt;br&gt;
✅ And maybe… just go inline&lt;/p&gt;




&lt;h2&gt;
  
  
  💬 Have You Seen This?
&lt;/h2&gt;

&lt;p&gt;If you’ve hit this bug (or others like it), drop a comment.&lt;br&gt;
If this saved you time, please share it — I genuinely hope it helps someone avoid what I went through.&lt;/p&gt;

&lt;p&gt;Thanks for reading. 👨🏾‍💻&lt;/p&gt;




&lt;h3&gt;
  
  
  Tags:
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;#reactnative&lt;/code&gt; &lt;code&gt;#expo&lt;/code&gt; &lt;code&gt;#nativewind&lt;/code&gt; &lt;code&gt;#reactnavigation&lt;/code&gt; &lt;code&gt;#debugging&lt;/code&gt; &lt;code&gt;#cssinterop&lt;/code&gt; &lt;code&gt;#mobiledev&lt;/code&gt; &lt;code&gt;#javascript&lt;/code&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>reactnavigation</category>
      <category>nativewind</category>
      <category>mobiledev</category>
    </item>
  </channel>
</rss>
