Troubleshooting
Common issues and their solutions.
TypeScript className Errors
Section titled “TypeScript className Errors”If TypeScript doesn’t recognize the className prop on React Native components:
Solution
Section titled “Solution”- Create the type declaration file:
import "@mgcrea/react-native-tailwind/react-native";- Verify it’s covered by your
tsconfig.jsonincludepattern:
{ "include": ["src/**/*"]}- Restart TypeScript server:
- VS Code: Cmd+Shift+P → “TypeScript: Restart TS Server”
- Or restart your editor
Babel Plugin Not Working
Section titled “Babel Plugin Not Working”If className props aren’t being transformed:
Solution
Section titled “Solution”Clear Metro cache:
npx react-native start --reset-cacheVerify babel.config.js:
module.exports = { presets: ["module:@react-native/babel-preset"], plugins: [ "@mgcrea/react-native-tailwind/babel", // Make sure this is present ],};Check plugin is loaded:
Look for transformation in your bundled code. The className props should be replaced with style props.
Custom Colors Not Recognized
Section titled “Custom Colors Not Recognized”If custom colors from tailwind.config.* aren’t working:
Solution
Section titled “Solution”-
Config location: Must be in project root or parent directory
-
Config format: Verify proper export
// CommonJSmodule.exports = { theme: { extend: { colors: { ... } } } };
// ESMexport default { theme: { extend: { colors: { ... } } } };- Clear cache: Config changes require Metro cache reset
npx react-native start --reset-cache- Use
theme.extend.colors: Don’t usetheme.colorsdirectly (overrides defaults)
// ✅ Good{ theme: { extend: { colors: { primary: "#1d4ed8" } } }}
// ❌ Bad (overrides all defaults){ theme: { colors: { primary: "#1d4ed8" } }}Dynamic className Warning
Section titled “Dynamic className Warning”If you see warnings about dynamic className:
Understanding
Section titled “Understanding”The Babel plugin only processes static strings at compile time. Runtime variables in class names can’t be parsed.
Solution
Section titled “Solution”// ❌ Doesn't work - runtime variableconst spacing = 4;<View className={`p-${spacing}`} />
// ✅ Use inline style for dynamic values<View className="border-2" style={{ padding: spacing * 4 }} />
// ✅ Or use conditional expressions (hybrid optimization)<View className={spacing === 4 ? "p-4" : "p-8"} />
// ✅ Or use runtime tw for fully dynamic needsimport { tw } from "@mgcrea/react-native-tailwind/runtime";<View style={tw`p-${spacing}`} />State Modifiers Not Working
Section titled “State Modifiers Not Working”If active:, focus:, or disabled: modifiers aren’t working:
Solution
Section titled “Solution”State modifiers require using the enhanced components from this package:
// ❌ Wrong - using React Native's Pressableimport { Pressable } from "react-native";<Pressable className="active:bg-blue-700" />
// ✅ Correct - using enhanced Pressableimport { Pressable } from "@mgcrea/react-native-tailwind";<Pressable className="active:bg-blue-700" />Same for TextInput:
// ❌ Wrongimport { TextInput } from "react-native";
// ✅ Correctimport { TextInput } from "@mgcrea/react-native-tailwind";Color Scheme Modifiers Not Working
Section titled “Color Scheme Modifiers Not Working”If dark: or light: modifiers aren’t working:
Common Causes
Section titled “Common Causes”- Class components: Color scheme modifiers require functional components (uses hooks)
// ❌ Doesn't work - class componentclass MyComponent extends React.Component { render() { return <View className="dark:bg-gray-900" />; }}
// ✅ Works - functional componentfunction MyComponent() { return <View className="dark:bg-gray-900" />;}-
React Native version: Requires React Native 0.62+ for
useColorScheme()hook -
Nested functions: Color scheme modifiers in
twtemplate must be at component level
// ❌ Doesn't work - nested functionfunction MyComponent() { const getStyles = () => tw`dark:bg-gray-900`; // Hook injection would violate Rules of Hooks}
// ✅ Works - component levelfunction MyComponent() { const styles = tw`dark:bg-gray-900`;}Styles Not Applying
Section titled “Styles Not Applying”If styles aren’t being applied to components:
Solution
Section titled “Solution”-
Check component support: Not all React Native components support all style properties
-
Verify prop name: Make sure you’re using the correct style prop name
// ScrollView content container<ScrollView contentContainerClassName="..." /> // ✅<ScrollView className="..." /> // ❌ (won't style content)-
Check style conflicts: Later styles may override earlier ones
-
Inspect generated code: Look at the transformed output to verify styles are being generated
Build Errors
Section titled “Build Errors”If you encounter build errors after installing:
Solution
Section titled “Solution”- Clear all caches:
# Clear Metro cachenpx react-native start --reset-cache
# Clear Watchman (if using)watchman watch-del-all
# Clear node_modules and reinstallrm -rf node_modulesnpm install
# iOS: Clear pods and reinstallcd ios && rm -rf Pods Podfile.lock && pod install && cd ..
# Clear build foldersrm -rf ios/build android/build android/app/build- Rebuild:
# iOSnpx react-native run-ios
# Androidnpx react-native run-androidPerformance Issues
Section titled “Performance Issues”If you experience slow build times:
Understanding
Section titled “Understanding”The Babel plugin parses className strings at build time, which adds some overhead to the compilation process.
- Use static className strings when possible (faster to parse)
- Avoid extremely long className strings
- Consider splitting complex components into smaller ones
- The overhead is typically 50-200ms per file
Getting Help
Section titled “Getting Help”If you can’t resolve your issue:
- Search existing issues: GitHub Issues
- Create a minimal reproduction: Isolate the problem in a small example
- Include details:
- React Native version
- Package version
- Babel configuration
- Error messages
- Code sample
Related
Section titled “Related”- Babel Configuration - Plugin options
- Custom Colors - Theme configuration
- Quick Start - Setup guide