Skip to content

fix: add Metro main/react-native fallbacks for the root entry - #683

Open
antoinerousseau wants to merge 1 commit into
uni-stack:mainfrom
antoinerousseau:fix/metro-main-field-fallback
Open

antoinerousseau wants to merge 1 commit into
uni-stack:mainfrom
antoinerousseau:fix/metro-main-field-fallback

Conversation

@antoinerousseau

@antoinerousseau antoinerousseau commented Sep 21, 2026

Copy link
Copy Markdown

Summary

Metro still consults react-native / main when it does not use exports (file-map miss, installer stub, older resolvers). Without those fields it defaults main to index, which this package does not ship:

Unable to resolve "uniwind"
… package.json was successfully found. However, this package itself specifies a
`main` module field that could not be resolved (`…/uniwind/index`).
  • Set react-native to ./src/index.ts (same as exports["."].react-native).
  • Set main to ./dist/common/index.js (same as exports["."].default).
  • List react-native first in the "." export map so condition matching prefers the native entry.

Fixes the OSS side of #682 (and the same error in #679).

This does not replace #570's origin pin, and it cannot change Uniwind Pro 1.7 (closed source / separate payload). Pro still needs that pin backported; apps that hoist a second uniwind may still need to load uniwind/metro from the Pro copy.

Test plan

  • import { Uniwind } from "uniwind" bundles with Expo SDK 57 / Metro when exports is skipped (no index fallback).
  • Native still resolves src/index.ts via react-native / exports.
  • Node/web still resolve dist/common/index.js via main / default.

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes

    • Improved package entry-point resolution for React Native and Metro environments.
    • Ensured native builds prioritize the React Native entry point when resolving the package root.
    • Added fallback entry metadata to support environments that do not process package export maps.
  • Documentation

    • Updated package documentation to describe the available entry points and resolution behavior.

Metro still consults `react-native` / `main` when it skips `exports`.
Without those fields it looks for `index`, which does not exist.
List `react-native` first in the `.` export map so native resolution
wins condition matching.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: d8fab439-5027-4ce3-8fc4-700f1c5c2f07

📥 Commits

Reviewing files that changed from the base of the PR and between 6766810 and 1c5b23d.

📒 Files selected for processing (2)
  • CONTEXT.md
  • packages/uniwind/package.json

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The package metadata now defines react-native and main fallback entries. The "." export prioritizes the react-native condition. CONTEXT.md documents these changes.

Changes

Package entry resolution

Layer / File(s) Summary
Root entry metadata
packages/uniwind/package.json, CONTEXT.md
The package adds react-native and main fields. The "." export lists react-native first. The documentation describes the updated resolution behavior.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: brentlok

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding Metro-compatible main and react-native fallbacks for the package root entry.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Sep 21, 2026

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

The PR is not yet safe to merge because the newly added main fallback points to a CommonJS .js artifact that Node interprets as ESM.

Fix All in Claude CodeFindings

  1. P1 Main target has wrong format

Summary

This PR adds root-level Metro-compatible package fallbacks and documents the resolver behavior.

  • Adds react-native and main root entry fields.
  • Prioritizes the react-native condition in the root export map.
  • Updates CONTEXT.md to describe the fallback contract.
  • The new main target has a module-format mismatch that prevents Node-compatible fallback loading.

Reviews (1) · Last reviewed commit: "fix: add Metro fallbacks for the root un..."

"style": "./uniwind.css",
"source": "src/index",
"react-native": "./src/index.ts",
"main": "./dist/common/index.js",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Main target has wrong format

When a legacy Node-compatible resolver uses the new main fallback, it loads dist/common/index.js. That file is generated as CommonJS, but the enclosing package declares "type": "module", so Node treats the .js file as ESM and require() cannot load it. As a result, consumers relying on the new fallback still cannot import the root package. Emit the artifact as .cjs or give dist/common a package manifest declaring "type": "commonjs".

Fix in Claude Code Fix in Codex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant