Skip to content

Fix package.json for react-native #206

@qnp

Description

@qnp

Environment

React Native / Metro

Reproduction

The lib is not usable in React Native context.
Metro won't resolve properly the correct build in package.json:

  • He, by default, will look at "main" entry which is the node one.
  • He also fails because he expects the entry package.json in "exports" (don't ask me why).
    (one could be inspired by axios package.json which is well tested for node, browser and react-native)

Describe the bug

  1. React Native app will fail on import http from 'node:http' because it uses the node build.
  2. Then, if corrected, it will ignore the package because package.json is not found in package.json 🙈

Additional context

In package.json, do these updates:

-    "main": "./cjs/node.cjs",
+    "main": "./cjs/index.cjs",

and

  "exports": {
+    "./package.json": "./package.json"

Beware that this should also be done in all unjs (awesomes) packages so that they can be used standalone in React Native.

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions