Skip to content

fix: fail when exact template version does not exist#2764

Merged
fabriziocucci merged 1 commit intomainfrom
fc-fail-if-version-does-not-match
Feb 6, 2026
Merged

fix: fail when exact template version does not exist#2764
fabriziocucci merged 1 commit intomainfrom
fc-fail-if-version-does-not-match

Conversation

@fabriziocucci
Copy link
Collaborator

Description

Problem:
When running npx @react-native-community/cli init MyApp --version "0.83.3", if the template for version 0.83.3 doesn't exist but 0.83.2 exists, the CLI would silently fall back to 0.83.2 instead of failing.

This caused real problems:

  1. rn-diff-purge breakage: The release job would succeed even when the requested template version didn't exist, because the CLI silently used a different template. This led to incorrect diffs being generated.

  2. Confusing user experience: Users would see Welcome to React Native 0.83.3 in the console output, but when they checked their package.json, they'd find a different version. This mismatch is confusing and can lead to debugging headaches.

Solution:
Removed the minor version fallback logic in getTemplateVersion(). The CLI now only matches exact MAJOR.MINOR.PATCH versions. If the requested version doesn't have a corresponding template, an error is thrown with a clear message.

Changes

File Change
packages/cli/src/tools/npm.ts Removed minor version fallback logic and unused minorVersion helper
packages/cli/src/commands/init/version.ts Added error handling when template version is not found
packages/cli/src/tools/__tests__/npm-test.ts Updated test to expect undefined for non-existent versions

Test Plan

# Should fail with error message
node packages/cli/build/bin.js init Test0833 --version "0.83.3" --skip-install
# Error: Unable to find a template for react-native version '0.83.3'...

# Should succeed (if 0.83.2 template exists)
node packages/cli/build/bin.js init Test0832 --version "0.83.2" --skip-install

# Unit tests
yarn test packages/cli/src/tools/__tests__/npm-test.ts

@fabriziocucci fabriziocucci changed the title Fail when exact template version does not exist fix: fail when exact template version does not exist Feb 6, 2026
@fabriziocucci fabriziocucci merged commit 6140100 into main Feb 6, 2026
8 checks passed
@fabriziocucci fabriziocucci deleted the fc-fail-if-version-does-not-match branch February 6, 2026 17:02
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 this pull request may close these issues.

2 participants