Skip to content

Metro cannot resolve uniwind: package.json has exports but no main #679

Description

@cursor

Problem

Metro (Expo SDK 57 / expo export) fails to resolve import { Uniwind } from "uniwind" with:

Error: While trying to resolve module `uniwind` from file `.../_layout.tsx`,
the package `.../node_modules/uniwind/package.json` was successfully found.
However, this package itself specifies a `main` module field that could not be resolved
(`.../node_modules/uniwind/index`).

packages/uniwind/package.json (v1.12.0, and the Uniwind Pro payload) has an exports map but no top-level main or react-native field. Metro then defaults main to index, which does not exist.

This is the same class of failure as facebook/metro#1424.

Expo's resolver also matches exports conditions in key order. The "." map currently starts with "style": "./uniwind.css", then "types", then "browser", and only later "react-native". If package exports are skipped or fail, there is no main fallback.

Repro context

We hit this in a pnpm workspace that also has a second app depending on public uniwind, while another app aliases Uniwind Pro:

"uniwind": "npm:uniwind-pro@^1.7.0"

With publicHoistPattern: "*", Node's require("uniwind/metro") can walk past the Pro installer stub and load the public package. Metro then bundles against the stub/payload that has no main.

Suggested fix

In packages/uniwind/package.json:

"main": "./src/index.ts",
"react-native": "./src/index.ts"

(using the same path as exports["."].react-native)

Optionally put "react-native" before "style" in the "." exports map so Expo's key-order matching prefers the native entry.

Happy to send a PR if that's useful.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions