Skip to content

Runtime crash with @react-navigation/elements CSS template literal #273

Description

@Babayev03

Bug: uniwind transformer causes runtime crash with @react-navigation/elements

Environment

  • Expo SDK 54
  • React Native 0.81.5 (New Architecture enabled)
  • uniwind (latest)
  • @react-navigation/native-stack ^7.8.6
  • @react-navigation/elements 2.9.3

Error

TypeError: Cannot convert undefined value to object

Runtime crash when importing @react-navigation/elements (directly or via @react-navigation/native-stack).

Root Cause

The CSS template literal in @react-navigation/elements/lib/module/PlatformPressable.js conflicts with uniwind's Metro transformer:

const css = String.raw;
const CSS_TEXT = css`
  .__react-navigation_elements_Pressable_hover {
    position: absolute;
    ...
  }
`;

Reproduction

  1. Create Expo project with React Navigation 7 and uniwind
  2. Enable package exports (required for React Navigation 7):
    config.resolver.unstable_enablePackageExports = true
  3. Import any navigator from @react-navigation/native-stack
  4. App crashes at runtime

Tested Configurations

Configuration Result
No uniwind + package exports ✅ Works
uniwind + package exports ❌ Crashes
uniwind + no package exports ❌ Crashes
Custom transformer skipping @react-navigation ❌ Crashes
Empty CSS file with uniwind ❌ Crashes

Workaround / Resolution

Option 1: Yarn Patch (Recommended)

  1. Start the patch:

    yarn patch @react-navigation/elements
  2. Edit lib/module/PlatformPressable.js in the temp folder - replace lines 97-144 with:

    // PATCHED: Removed CSS template literal that conflicts with uniwind
    const HoverEffect = ({ color, hoverOpacity = 0.08, activeOpacity = 0.16 }) => {
      if (Platform.OS !== 'web' || color == null) {
        return null;
      }
      return null;
    };
  3. Commit the patch:

    yarn patch-commit -s <temp-folder-path>
  4. Run yarn install to apply

This patch survives yarn install, npx expo prebuild, and reinstalls.

Option 2: Fix in uniwind

uniwind should handle/skip CSS template literals in node_modules packages to avoid conflicts with third-party libraries.

Expected Behavior

uniwind should handle or skip files containing CSS template literals from third-party packages without causing runtime crashes.


This issue was created with the assistance of Claude Code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions