Skip to content

Troubleshooting

Common issues and their solutions.

If TypeScript doesn’t recognize the className prop on React Native components:

  1. Create the type declaration file:
src/types/react-native-tailwind.d.ts
import "@mgcrea/react-native-tailwind/react-native";
  1. Verify it’s covered by your tsconfig.json include pattern:
{
"include": ["src/**/*"]
}
  1. Restart TypeScript server:
    • VS Code: Cmd+Shift+P → “TypeScript: Restart TS Server”
    • Or restart your editor

If className props aren’t being transformed:

Clear Metro cache:

Terminal window
npx react-native start --reset-cache

Verify 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.

If custom colors from tailwind.config.* aren’t working:

  1. Config location: Must be in project root or parent directory

  2. Config format: Verify proper export

// CommonJS
module.exports = { theme: { extend: { colors: { ... } } } };
// ESM
export default { theme: { extend: { colors: { ... } } } };
  1. Clear cache: Config changes require Metro cache reset
Terminal window
npx react-native start --reset-cache
  1. Use theme.extend.colors: Don’t use theme.colors directly (overrides defaults)
// ✅ Good
{
theme: {
extend: {
colors: { primary: "#1d4ed8" }
}
}
}
// ❌ Bad (overrides all defaults)
{
theme: {
colors: { primary: "#1d4ed8" }
}
}

If you see warnings about dynamic className:

The Babel plugin only processes static strings at compile time. Runtime variables in class names can’t be parsed.

// ❌ Doesn't work - runtime variable
const 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 needs
import { tw } from "@mgcrea/react-native-tailwind/runtime";
<View style={tw`p-${spacing}`} />

If active:, focus:, or disabled: modifiers aren’t working:

State modifiers require using the enhanced components from this package:

// ❌ Wrong - using React Native's Pressable
import { Pressable } from "react-native";
<Pressable className="active:bg-blue-700" />
// ✅ Correct - using enhanced Pressable
import { Pressable } from "@mgcrea/react-native-tailwind";
<Pressable className="active:bg-blue-700" />

Same for TextInput:

// ❌ Wrong
import { TextInput } from "react-native";
// ✅ Correct
import { TextInput } from "@mgcrea/react-native-tailwind";

If dark: or light: modifiers aren’t working:

  1. Class components: Color scheme modifiers require functional components (uses hooks)
// ❌ Doesn't work - class component
class MyComponent extends React.Component {
render() {
return <View className="dark:bg-gray-900" />;
}
}
// ✅ Works - functional component
function MyComponent() {
return <View className="dark:bg-gray-900" />;
}
  1. React Native version: Requires React Native 0.62+ for useColorScheme() hook

  2. Nested functions: Color scheme modifiers in tw template must be at component level

// ❌ Doesn't work - nested function
function MyComponent() {
const getStyles = () => tw`dark:bg-gray-900`; // Hook injection would violate Rules of Hooks
}
// ✅ Works - component level
function MyComponent() {
const styles = tw`dark:bg-gray-900`;
}

If styles aren’t being applied to components:

  1. Check component support: Not all React Native components support all style properties

  2. Verify prop name: Make sure you’re using the correct style prop name

// ScrollView content container
<ScrollView contentContainerClassName="..." /> // ✅
<ScrollView className="..." /> // ❌ (won't style content)
  1. Check style conflicts: Later styles may override earlier ones

  2. Inspect generated code: Look at the transformed output to verify styles are being generated

If you encounter build errors after installing:

  1. Clear all caches:
Terminal window
# Clear Metro cache
npx react-native start --reset-cache
# Clear Watchman (if using)
watchman watch-del-all
# Clear node_modules and reinstall
rm -rf node_modules
npm install
# iOS: Clear pods and reinstall
cd ios && rm -rf Pods Podfile.lock && pod install && cd ..
# Clear build folders
rm -rf ios/build android/build android/app/build
  1. Rebuild:
Terminal window
# iOS
npx react-native run-ios
# Android
npx react-native run-android

If you experience slow build times:

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

If you can’t resolve your issue:

  1. Search existing issues: GitHub Issues
  2. Create a minimal reproduction: Isolate the problem in a small example
  3. Include details:
    • React Native version
    • Package version
    • Babel configuration
    • Error messages
    • Code sample