Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make react-native peerDependency optional #269

Closed
trivikr opened this issue Mar 26, 2021 · 3 comments
Closed

Make react-native peerDependency optional #269

trivikr opened this issue Mar 26, 2021 · 3 comments

Comments

@trivikr
Copy link

trivikr commented Mar 26, 2021

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

When a project depends on react-native-url-polyfill 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-url-polyfill 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 platforms in 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": "*"
  },
  "peerDependenciesMeta": {
    "react-native": {
      "optional": true
    }
  },
  // ...
}

The peerDependenciesMeta is supported in:

Describe alternatives you've considered

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

Additional context

@trivikr
Copy link
Author

trivikr commented Mar 26, 2021

The RFC on yarn package manager which had introduced peerDependenciesMeta https://github.com/yarnpkg/rfcs/blob/master/accepted/0000-optional-peer-dependencies.md

@charpeni
Copy link
Owner

Oh, that’s really interesting! Thanks for your detailed issue, I wasn’t aware of that feature at all.

I like the solution you described.

@trivikr
Copy link
Author

trivikr commented Mar 26, 2021

Closing this request, as react-native is a required peer dependency for react-native-url-polyfill

The platform independent consumers (like aws-sdk-js-v3) which require react-native-url-polyfill for React Native support should make their peerDependency on react-native-url-polyfill optional instead. The consumers should also call out in their documentation that react-antive polyfills are required to be added by their consumers when using react-native environments.

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 a pull request may close this issue.

2 participants