Overview
ThewithNativewind function configures your Metro bundler to support NativeWind styling. This is a required step for integrating NativeWind into your React Native application.
Installation
The Metro configuration is exported from thenativewind/metro package:
Function Signature
Parameters
Your Metro configuration object or a function that returns a Promise resolving to a Metro configuration. This can be obtained from
@expo/metro-config or other Metro configuration sources.Optional configuration options for customizing NativeWind behavior.
Returns
Returns the enhanced Metro configuration with NativeWind transformations applied. The return type matches the input type, preserving type safety.
Usage
Basic Setup with Expo
metro.config.js
With Custom Options
metro.config.js
With Async Configuration
metro.config.js
ESM Syntax
metro.config.js
TypeScript Support
By default, NativeWind generates a
nativewind-env.d.ts file in your project root. This file provides TypeScript definitions for the className prop on React Native components.tsconfig.json includes the file:
tsconfig.json
metro.config.js
How It Works
Under the hood,withNativewind wraps the withReactNativeCSS function from react-native-css/metro with NativeWind-specific defaults:
- Enables global
classNamepolyfill for all components - Sets up TypeScript environment file generation
- Configures CSS processing for React Native
Legacy API
withNativeWind will be removed in a future version.
Troubleshooting
Metro bundler not picking up styles
Ensure you’ve cleared the Metro cache:TypeScript errors with className
Verify that thenativewind-env.d.ts file exists and is included in your TypeScript configuration. You may need to restart your TypeScript server in your editor.
Related
- Babel Configuration - Configure Babel for NativeWind
- Tailwind Plugin - Configure Tailwind CSS plugin
- Installation Guide - Complete setup guide