fix: Mark react-native-nitro-modules peer dependency as optional - #20
Merged
Conversation
Semver ranges never match pre-releases, so a required peer of "*" does not match e.g. 0.37.0-beta.0. Package managers then install a second, stable copy of Nitro next to the pre-release, and the native/JS version guard throws "Nitro was installed twice" at runtime. Marking the peer optional leaves the consuming app in full control of the installed Nitro version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Semver ranges never match pre-release versions unless a comparator shares the same
major.minor.patchtuple and carries a pre-release tag. So the"react-native-nitro-modules": "*"peer range does not match a version like0.37.0-beta.0:*>=0.0.0-0>=0.37.0-0Because the peer is required, bun satisfies it itself by installing a second, stable copy of
react-native-nitro-modulesnested inside this library. An app testing a Nitro pre-release then builds native against the pre-release while Metro bundles the stable JS, and Nitro throws at startup:Builds stay green - only runtime catches it.
Fix
Mark the peer optional, so the consuming app is the sole decider of the Nitro version. No range can express "anything, including future pre-releases" (
>=0.37.0-0just moves the breakage to 0.38.0-beta.0), so this has to be resolution behaviour rather than a cleverer range.Upstream fix in the Nitro template + docs: margelo/nitro#1516
Trade-off
optional: truealso suppresses the missing peer warning. Acceptable: a Nitro Module withoutreact-native-nitro-modulesfails loudly at build time (autolinking cannot find the pod / Gradle project), and version mismatches are caught by Nitro's runtime guard - strictly stronger than an install-time range check.The example app declares
react-native-nitro-modulesdirectly, so it is unaffected.Note
The
bun.lockdiff also syncs a stale workspaceversionfield that had drifted frompackage.json(pre-existing; anybun iproduces it).