<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged nativewind</title>
<link>https://coderlegion.com/tag/nativewind</link>
<description>Powered by Question2Answer</description>
<item>
<title>[48 Hours Lost] NativeWind + Expo Router = &quot;Couldn't find a navigation context&quot; Nightmare</title>
<link>https://coderlegion.com/4624/48-hours-lost-nativewind-expo-router-couldnt-find-a-navigation-context-nightmare</link>
<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;hr&gt;
&lt;h3 id=&quot;the-error&quot;&gt;The Error&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;&quot;Couldn't find a navigation context.&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you're here, you’ve probably seen this and thought:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&quot;Ah, I must’ve forgotten to wrap something with &lt;code&gt;NavigationContainer&lt;/code&gt;.&quot;&lt;br&gt;
&quot;Maybe the layout is off.&quot;&lt;br&gt;
&quot;Is React Navigation broken?&quot;&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;hr&gt;
&lt;h3 id=&quot;the-real-culprit-css-interop-race-condition&quot;&gt;The Real Culprit: CSS Interop Race Condition&lt;/h3&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;hr&gt;
&lt;h3 id=&quot;-problematic-nativewind-classes&quot;&gt;⚠️ Problematic NativeWind Classes&lt;/h3&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;hr&gt;
&lt;h3 id=&quot;the-symptom&quot;&gt;The Symptom&lt;/h3&gt;
&lt;p&gt;If you're hitting any of these:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&quot;Couldn't find a navigation context&quot;&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;hr&gt;
&lt;h3 id=&quot;-the-fix-use-inline-styles&quot;&gt;✅ The Fix: Use Inline Styles&lt;/h3&gt;
&lt;p&gt;Replace the problematic class names with direct &lt;code&gt;style&lt;/code&gt; props.&lt;/p&gt;
&lt;h4 id=&quot;-before-&quot;&gt;❌ Before:&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&amp;lt;TouchableOpacity className=&quot;bg-white/15 shadow-sm opacity-50&quot;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;-after-&quot;&gt;✅ After:&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&amp;lt;TouchableOpacity 
  style={{
    backgroundColor: 'rgba(255, 255, 255, 0.15)',
    shadowOffset: { width: 0, height: 1 },
    shadowOpacity: 0.05,
    shadowRadius: 2,
    opacity: 0.5
  }}
&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This completely solved the issue in my project.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;tech-stack&quot;&gt;Tech Stack&lt;/h3&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;hr&gt;
&lt;h3 id=&quot;why-this-matters&quot;&gt;Why This Matters&lt;/h3&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;hr&gt;
&lt;h3 id=&quot;-what-i-did&quot;&gt;✅ What I Did&lt;/h3&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 rel=&quot;nofollow&quot; href=&quot;https://github.com/marklawlor/nativewind&quot;&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;hr&gt;
&lt;h3 id=&quot;final-thoughts&quot;&gt;Final Thoughts&lt;/h3&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;hr&gt;
&lt;h3 id=&quot;have-you-seen-this-&quot;&gt;Have You Seen This?&lt;/h3&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;hr&gt;
&lt;h4 id=&quot;tags-&quot;&gt;Tags:&lt;/h4&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>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/4624/48-hours-lost-nativewind-expo-router-couldnt-find-a-navigation-context-nightmare</guid>
<pubDate>Tue, 12 Aug 2025 13:38:49 +0000</pubDate>
</item>
</channel>
</rss>