Generate React CLI
generate-react-cli is a command-line interface tool designed to streamline the creation of React components, aiming to boost developer productivity by automating repetitive setup tasks. The current stable version is 11.0.4, released in April 2026. This package maintains a somewhat frequent release cadence, with multiple minor and patch releases occurring monthly or bi-monthly, and major versions typically updating Node.js requirements or tooling support. Its key differentiators include an initial interactive configuration that generates a `generate-react-cli.json` file, allowing project-specific defaults for TypeScript usage, CSS modules, various CSS preprocessors (like SCSS), and testing libraries (React Testing Library, Vitest, or no tests). It offers extensive customization through command-line options and support for custom component types, templates, and file structures, enabling developers to quickly scaffold components, pages, or layouts according to their project's conventions.
Common errors
-
Error: You are running Node.js <22.
cause The installed version of Node.js does not meet the minimum requirement (Node.js 22 or higher) for `generate-react-cli` versions 10.0.0 and above.fixUpgrade your Node.js environment to version 22 or newer. Using a Node Version Manager (nvm) is recommended for easy switching: `nvm install 22 && nvm use 22`. -
Error: generate-react-cli.json: No such file or directory
cause The configuration file `generate-react-cli.json` is missing from your project root, or the CLI has not been run previously to create it automatically.fixRun `npx generate-react-cli component MyComponent` once. This command will interactively prompt you to set up initial configurations and then create the `generate-react-cli.json` file in your project root. -
Cannot find module 'YourComponentName.module.css' (or similar style import error)
cause The generated component is attempting to import a CSS module, but either the `usesCssModule` setting in `generate-react-cli.json` or the `--withStyle` option was incorrectly configured for your project's styling setup, or the style file was not generated as expected.fixVerify the `usesCssModule` and `cssPreprocessor` settings in your `generate-react-cli.json`. Ensure `withStyle` is `true` if you expect a style file. Adjust your project's Webpack/Vite configuration to correctly handle CSS modules if necessary.
Warnings
- breaking Minimum Node.js version required to run `generate-react-cli` has been raised to 22.0 or higher.
- breaking Support for the Enzyme testing library has been removed. Projects using Enzyme for tests will need to migrate to Testing Library or Vitest.
- gotcha The CLI generates a `generate-react-cli.json` configuration file in your project root on its first run. This file dictates default settings for component generation.
Install
-
npm install generate-react-cli -
yarn add generate-react-cli -
pnpm add generate-react-cli
Quickstart
npx generate-react-cli component Box # The first command will prompt you to configure the CLI, creating a # 'generate-react-cli.json' file. Then it generates a 'Box' component. # Subsequent runs can override configured defaults using options: npx generate-react-cli component Button --withTest=false --withStory=true # For global installation (less recommended for CI/CD environments): npm i -g generate-react-cli generate-react component Navbar