How to Check React Version on CMD: 7 Fast Command Line Methods

Use npm list react --depth=0 to instantly display the installed React version, or run node -p "require('react/package.json').version" to check react version on cmd without package manager overhead.

When debugging dependency conflicts or verifying environment setup, developers frequently need to check react version on cmd to confirm which release is actively running in a project. The facebook/react repository organizes its codebase as a Yarn workspace monorepo, where the canonical version resides in packages/react/package.json, but installed projects retrieve this metadata through package manager lockfiles.

Method 1: Using npm (Most Common)

The fastest way to verify your React version with npm relies on the ls command with depth limiting to avoid traversing the entire dependency tree.

Quick Check with npm list

npm list react --depth=0

This outputs a single line showing the exact version installed at the project root, such as [email protected]. The --depth=0 flag ensures the command runs in O(1) time relative to your project size by reading only the top-level lockfile entry.

JSON Output for Scripting

For CI/CD pipelines or automated scripts, use the JSON formatter:

npm ls react --depth=0 --json

This returns a structured object containing the version field, making it easy to parse with tools like jq or Node.js scripts.

Method 2: Using Yarn

Yarn provides different commands depending on whether you use Classic (v1) or Berry (v2+).

Yarn Classic

yarn list --pattern react --depth=0

This mirrors npm's behavior, displaying the resolved version from the yarn.lock file without descending into sub-dependencies.

Yarn Berry (v2+)

Modern Yarn versions use the why command for detailed resolution:

yarn why react

The output includes the exact version identifier (e.g., react@npm:19.3.0) and explains why this specific version was resolved, which helps debug version conflicts in complex monorepos.

Method 3: Using pnpm

For projects using pnpm, the syntax closely follows npm:

pnpm list react --depth=0

This reads from pnpm's content-addressable store and lockfile (pnpm-lock.yaml) to return the installed version instantly.

Method 4: Direct File Access (No Package Manager)

When you need to check react version on cmd without package manager overhead, read the package.json file directly from node_modules:

node -p "require('./node_modules/react/package.json').version"

This executes in milliseconds because it performs a single file read operation. Alternatively, use shell utilities:

cat node_modules/react/package.json | grep '"version"'

Both methods bypass lockfile parsing entirely, making them the fastest option when node_modules exists.

How React Versioning Works in the Source Code

Understanding the source helps explain why these commands work. In the facebook/react repository, the canonical version string lives in packages/react/package.json:

{
  "name": "react",
  "version": "19.3.0"
}

The repository uses Yarn workspaces defined in the root package.json ("workspaces": ["packages/*"]), allowing the build system to synchronize versions across react, react-dom, and other packages. When you install React via npm or Yarn, the package manager copies this version field into your local node_modules and records it in your lockfile.

For React core developers, the repository includes a validation script at scripts/tasks/version-check.js that ensures version consistency across the monorepo before publishing.

Summary

  • Use npm list react --depth=0 for the fastest, most common way to check react version on cmd.
  • Use node -p "require('react/package.json').version" when you need instant results without package manager overhead.
  • Use yarn why react (Berry) or yarn list --pattern react (Classic) for Yarn-based projects.
  • Use pnpm list react --depth=0 for pnpm environments.
  • All methods read from packages/react/package.json in the facebook/react source, which serves as the single source of truth for version 19.3.0 and future releases.

Frequently Asked Questions

How do I check react version on cmd without npm or yarn installed?

Use the Node.js runtime directly to read the package metadata: node -p "require('./node_modules/react/package.json').version". This requires only Node.js and a populated node_modules directory, bypassing the need for npm, yarn, or pnpm binaries.

Why does my cmd show a different react version than my package.json?

Your package.json specifies a version range (e.g., ^18.0.0), while the command line shows the exact resolved version (e.g., 18.2.0) recorded in your lockfile (package-lock.json, yarn.lock, or pnpm-lock.yaml). The lockfile pins the exact dependency tree installed in node_modules, which may differ from the range allowed in package.json.

How do I check the react version in the source code repository itself?

Clone the facebook/react repository and run git grep -n '"version":' packages/react/package.json or simply view packages/react/package.json. The "version" field contains the current development version (e.g., 19.3.0 on the main branch). This differs from installed versions because the repository represents the source of truth before publishing to the npm registry.

Which command is fastest for checking react version in CI/CD pipelines?

npm ls react --depth=0 --json executes fastest in automated environments because it performs a single lookup in the lockfile without traversing child dependencies. The --json flag ensures machine-readable output that CI systems can parse reliably. For even faster execution in containerized environments where node_modules is cached, use node -p "require('react/package.json').version" which reads one file directly.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →