Do You Need to Manually Update Dependencies When Upgrading React?
No, npm does not automatically update dependency version strings in your package.json files when upgrading React; you must either manually edit the version fields or use React's official release automation scripts to synchronize inter-package dependencies.
When working with the facebook/react repository—a monorepo managed via Yarn workspaces—upgrading React requires careful coordination across multiple package.json files. While npm and Yarn install the versions you declare, they do not automatically rewrite those declarations when you perform a repository upgrade. This guide explains how to properly update dependencies when upgrading React, whether through manual editing or the automated release scripts provided in the repository.
How React's Monorepo Structures Dependencies
The React codebase organizes code as a monorepo with a root package.json and individual packages nested under the packages/ directory.
Root vs. Package-Level Dependencies
The root package.json declares the workspace layout and development dependencies required for building and testing the entire repository (see lines 3‑5 in the root package.json). These dev-dependencies include build tools, test runners, and linting utilities that apply to the whole monorepo but are not shipped to end users.
In contrast, each published package maintains its own package.json within the packages/ directory. For example, packages/react/package.json defines React's public API and version (line 7), while packages/react-dom/package.json contains the renderer-specific configuration.
Inter-Package Dependencies and Peer Dependencies
Individual packages declare their relationships through two critical fields:
dependencies: Runtime requirements between packages. For instance,react-domdepends onscheduler, as shown inpackages/react-dom/package.jsonlines 19‑22.peerDependencies: Compatibility constraints on the React version expected. Thereact-dompackage declaresreactas a peer dependency in lines 36‑41 of itspackage.json, ensuring the renderer matches the core library version.
When you upgrade React, these version strings must remain synchronized across all packages. If react bumps to 19.3.0, react-dom must update its peerDependencies to require ^19.3.0 and its own version field must reflect the new release.
Why npm Does Not Automatically Update Dependencies
Package managers like npm and Yarn resolve and install the versions declared in your package.json files, but they do not automatically rewrite those declarations when you perform a repository upgrade.
When you run npm update or yarn upgrade, the package manager consults the existing version ranges and installs the latest compatible versions within those ranges. However, the actual strings in package.json—such as "react": "^19.2.0"—remain unchanged unless you explicitly modify them or use a helper script.
In the context of the React monorepo, this means that bumping the version in packages/react/package.json does not cascade to packages/react-dom/package.json or other dependent packages. You must explicitly update the version, dependencies, and peerDependencies fields to reflect the new release.
Two Methods to Update Dependencies When Upgrading React
React maintainers use two primary approaches to synchronize version numbers across the monorepo: manual editing or the official release automation scripts.
Manual Editing of package.json Files
You can manually update each package's metadata by editing the relevant package.json files directly:
- Update the
versionfield inpackages/react/package.json(line 7) to the new release number (e.g.,19.3.0). - Update the
versionfield inpackages/react-dom/package.jsonand other packages accordingly. - Modify the
peerDependenciesin dependent packages (e.g., lines 36‑41 inpackages/react-dom/package.json) to require the new React version. - Update any
dependenciesbetween packages (e.g.,schedulerreferences inreact-dom) to ensure they match the new release.
While straightforward for small patches, this approach becomes error-prone across React's many packages (react, react-dom, react-reconciler, scheduler, etc.).
Using the Official Release Automation Script
The React team provides an automated solution via scripts/release/prepare-release-from-npm.js. This script orchestrates the promotion of a "next" build to a stable release while automatically updating all version strings.
The script executes the following workflow (starting at line 44):
getLatestNextVersion: Retrieves the most recent "next" build from npm.guessStableVersionNumbers: Generates proposed stable version numbers based on the next build.confirmStableVersionNumbers: Prompts the maintainer to confirm or adjust the proposed versions.updateStableVersionNumbers: Writes the confirmed version numbers back to everypackage.jsonin the monorepo, including alldependenciesandpeerDependencies.
To execute the automation:
# From the repository root
node scripts/release/prepare-release-from-npm.js --version=19.3.0
This approach ensures that packages/react/package.json, packages/react-dom/package.json, and all other packages receive synchronized version bumps without manual editing.
Validating Dependency Consistency
After updating versions—whether manually or via script—you should verify that all inter-package dependencies remain consistent. React provides a validation utility at scripts/release/check-release-dependencies.js.
This script contains a checkDependency function (lines 48‑55) that validates every intra-repo dependency satisfies the expected semver range. If any package references an outdated version of another monorepo package, the script throws an error and halts the release process.
Run the validation:
node scripts/release/check-release-dependencies.js
This safety check prevents publishing packages with mismatched dependencies, ensuring that react-dom always declares compatible peerDependencies on the corresponding react version.
Summary
- npm does not automatically update the version strings in
package.jsonfiles when you upgrade React; it only installs the versions already declared. - React's monorepo structure requires synchronizing versions across multiple packages (
react,react-dom,scheduler, etc.) including bothdependenciesandpeerDependencies. - You have two options for updating: manual editing of each
package.jsonor using the automated release script atscripts/release/prepare-release-from-npm.js. - Always run
scripts/release/check-release-dependencies.jsto validate that all inter-package version ranges are consistent before publishing.
Frequently Asked Questions
Does npm update package.json automatically when I run npm update?
No, npm installs the latest versions that satisfy the existing ranges in your package.json, but it does not automatically rewrite those version strings to reflect newer releases. The package.json file remains unchanged unless you manually edit it or use a release automation script like prepare-release-from-npm.js in the React repository.
What happens if I forget to update peerDependencies when upgrading React?
If you forget to update peerDependencies in packages like react-dom, npm will issue warnings or errors when users try to install the packages, indicating that the required React version is missing or incompatible. In the React monorepo, the check-release-dependencies.js script catches these mismatches by validating that all peerDependencies satisfy the expected semver ranges before any release is published.
Can I use npm instead of Yarn for React's release scripts?
While the React monorepo uses Yarn workspaces for dependency management as defined in the root package.json, the release scripts themselves are Node.js scripts that can be executed directly. However, the underlying package management during the release process assumes the Yarn workspaces structure. For consistency with the React team's workflow, Yarn is recommended, but the scripts at scripts/release/prepare-release-from-npm.js do not strictly require the yarn CLI to run.
How does React ensure all packages stay in sync during a release?
React ensures synchronization through the prepare-release-from-npm.js automation script, which updates the version, dependencies, and peerDependencies fields across all packages simultaneously. This script uses helper functions—getLatestNextVersion, guessStableVersionNumbers, confirmStableVersionNumbers, and updateStableVersionNumbers—to orchestrate the version bump consistently. Afterward, check-release-dependencies.js validates that every intra-repo dependency matches the expected ranges, preventing mismatched releases.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →