Skip to content

Make react-native peerDependency optional #27

Closed
@trivikr

Description

@trivikr

Is your feature request related to a problem? Please describe.

When a project depends on react-native-get-random-values and uses npm v7, the react-native peerDependency is installed by default. This happens as npm v7 automatically installs peer dependencies.

The npm v7 was made generally available on February 2, 2021, and is shipped with latest versions of Node.js

This is a problem, as some packages which depend on react-native-get-random-values may support all JavaScript platforms in a single package. Even if the consumers of those packages do not need support for react-native, the react-native dependency will be installed by default in npm v7.

An example is AWS SDK for JavaScript (v3) which supports Node.js, browser and react-native from a single package.

Describe the solution you'd like

Use peerDependenciesMeta configuration to set react-native dependency as optional in package.json as follows:

{
  // ...
  "peerDependencies": {
    "react-native": ">=0.56"
  },
  "peerDependenciesMeta": {
    "react-native": {
      "optional": true
    }
  },
  // ...
}

The peerDependenciesMeta is supported in:

Describe alternatives you've considered

Setting react-native-get-random-values as optional in projects which consume it.
Example in aws-sdk-js-v3 aws/aws-sdk-js-v3#2108

Additional context

This issue occurs when AWS SDK for JavaScript (v3) is installed using npm v7 aws/aws-sdk-js-v3#1536
The detailed suggestion on why react-native should be optional peerDependency in react-native-get-random-values aws/aws-sdk-js-v3#1536 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions