ReactJS Installation Guide

Prerequisites

Before installing React, ensure you have these installed:

  • Node.js (version 14 or later recommended)
  • npm (comes with Node.js) or Yarn (v1.22.0+)
  • A code editor (VS Code recommended)
  • Chrome Developer Tools for debugging

1. Installation Using create-react-app

Official Boilerplate

The easiest way to set up a React project:

npx create-react-app my-app
cd my-app
npm start

This creates:

  • Development environment with live reloading
  • Webpack for bundling
  • Babel for JSX/ES6+ transpilation
  • Jest for testing

2. Manual Setup (Advanced)

Step-by-Step Configuration

  1. Create project directory:
    mkdir react-manual-setup
  2. Initialize npm:
    npm init -y
  3. Install React:
    npm install react react-dom
  4. Install Babel:
    npm install @babel/core @babel/preset-env @babel/preset-react babel-loader --save-dev
  5. Install Webpack:
    npm install webpack webpack-cli webpack-dev-server html-webpack-plugin --save-dev
  6. Create webpack.config.js and configure loaders
  7. Set up Babel presets in .babelrc

3. CDN Links (Quick Testing)

For quick prototyping without local installation:

<!-- Development -->
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>

<!-- Production -->
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>

Add Babel standalone for JSX processing:

<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>

4. Using Vite (Modern Alternative)

Ultra-Fast Development

npm create vite@latest my-react-app --template react
cd my-react-app
npm install
npm run dev

Key advantages:

  • Native ES modules support
  • Instant server start
  • Lightning-fast HMR (Hot Module Replacement)
  • Optimized production build

Project Structure Comparison

create-react-app

my-app/
├── node_modules/
├── public/
│   ├── index.html
│   └── favicon.ico
├── src/
│   ├── App.css
│   ├── App.js
│   ├── index.js
│   └── index.css
├── package.json
└── README.md

Manual Setup

react-manual/
├── dist/
├── node_modules/
├── src/
│   ├── components/
│   ├── App.js
│   └── index.js
├── .babelrc
├── package.json
└── webpack.config.js

Post-Installation Steps

Essential Packages

Recommended additional installations:

npm install react-router-dom axios prop-types
npm install --save-dev @testing-library/react prettier eslint

Troubleshooting

Common Issues and Solutions:

IssueSolution
EACCES permissions errorRun sudo chown -R $(whoami) ~/.npm
Port 3000 already in useSet PORT=3001 before npm start
Missing dependenciesDelete node_modules and run npm install
Slow installationUse npm install --verbose to identify bottlenecks

Environment Setup Verification

Verify your React installation by creating a test component:

// src/App.js
import React from 'react';

function App() {
  return <h1>Hello React!</h1>;
}

export default App;

Then run the development server:

npm start

You should see "Hello React!" at http://localhost:3000