Skip to content

config ignores peerDependencies and instead reads devDependencies #2419

@tido64

Description

@tido64

Description

config ignores peerDependencies and instead reads devDependencies:

const deps = [
...Object.keys(pjson.dependencies || {}),
...Object.keys(pjson.devDependencies || {}),
];

This leads to errors in react-native-windows autolinking (and possibly in other scenarios) where dependencies are only declared under peerDependencies and not devDependencies, for instance in @react-native-webapis/web-storage we have the following:

{
  "peerDependencies": {
    "@callstack/react-native-visionos": ">=0.73",
    "react": ">=18.2.0",
    "react-native": ">=0.72",
    "react-native-macos": ">=0.72",
    "react-native-windows": ">=0.72"
  },
  "peerDependenciesMeta": {
    "@callstack/react-native-visionos": {
      "optional": true
    },
    "react-native-macos": {
      "optional": true
    },
    "react-native-windows": {
      "optional": true
    }
  },
  "devDependencies": {
    "react-native": "^0.73.0"
  }
}

In this case, config outputs:

  "platforms": {
    "ios": {},
    "android": {}
  },

If I add react-native-windows to devDependencies, config outputs:

  "platforms": {
    "ios": {},
    "android": {},
    "windows": {
      "npmPackageName": "react-native-windows"
    }
  },

In my opinion, the correct fix should be to replace devDependencies with peerDependencies, but I don't know if this will break current scenarios so we should probably keep it as is and just add peerDependencies to the list in findDependencies.ts.

Reproducible Demo

In any project, you can run the following:

yarn add @react-native-webapis/web-storage@0.2.6
cd node_modules/@react-native-webapis/web-storage
yarn react-native config

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions