Migrating from Create React App to Next.js: Lessons Learned
Create React App served the React ecosystem well, but its time has passed. CRA has been officially deprecated, its webpack configuration is frozen, and new projects are directed toward frameworks like Next.js, Vite, or Remix. If your production application still runs on CRA, you are accumulating technical debt with every passing month — missing out on server-side rendering, automatic code splitting, the App Router, and an ecosystem of tools optimized for modern React. This guide walks through a complete migration from CRA to Next.js 15, based on our experience migrating several client applications. For the broader question of choosing the right framework, see our comparison of Django vs WordPress for business websites.
Need help with web development? I provide web development for businesses ready to grow. Learn about my web development service or get in touch for a free consultation.
- Understand why Migrate Now
- Phase 3: Data Fetching Patterns
- Phase 6: CI/CD Pipeline Updates
- Common Migration Pitfalls
Why Migrate Now
Beyond the deprecation, there are concrete technical reasons to migrate today. CRA bundles your entire application into a single JavaScript file that the browser must download, parse, and execute before rendering anything. On a typical B2B SaaS dashboard, this means a 2-4 second blank white screen on first load. Next.js renders the initial page on the server and streams it to the browser, so users see content in under a second while JavaScript hydrates in the background.
Performance improvements translate directly to business metrics. Google's Core Web Vitals — LCP, FID, and CLS — are ranking factors for search. A CRA application with a 3.5-second LCP score lands in the "needs improvement" category, hurting your SEO. After migration, the same application typically achieves a sub-1.5-second LCP, landing solidly in "good" territory. For applications where SEO matters (marketing sites, documentation, blogs), this alone justifies the migration effort.
Developer experience improves as well. Next.js's file-based routing eliminates the need for react-router configuration. The App Router's server components reduce client-side JavaScript by moving data fetching and rendering logic to the server. And Turbopack, Next.js's bundler, offers 10x faster hot module replacement than webpack — a meaningful productivity gain on larger codebases.
Phase 1: Project Setup and Dependencies
Start by creating a fresh Next.js project alongside your CRA project. Do not try to convert your CRA project in place — a parallel migration lets you move pages incrementally and compare results side by side.
# Create new Next.js project
npx create-next-app@latest my-app-next --typescript --tailwind --app --src-dir
# Copy shared dependencies
# Compare package.json files and install shared libraries
npm install @tanstack/react-query axios date-fns zod
Audit your CRA dependencies before migrating them. Many CRA-era libraries have been superseded: react-router-dom is replaced by Next.js's built-in routing, react-helmet by Next.js's Metadata API, axios can often be replaced by fetch with server components, and state management libraries like Redux may be unnecessary when server components handle data fetching. Fewer dependencies mean faster builds, smaller bundles, and fewer security vulnerabilities.
On a typical B2B SaaS dashboard, this means a 2-4 second blank white screen on first load.
Phase 2: Routing Translation
CRA uses react-router for client-side routing. Next.js uses file-system routing where the directory structure defines your URL paths. This is the most mechanical part of the migration — tedious but straightforward.
# CRA routing (react-router)
# src/App.tsx
<Routes>
<Route path="/" element={<Dashboard />} />
<Route path="/projects" element={<ProjectList />} />
<Route path="/projects/:id" element={<ProjectDetail />} />
<Route path="/settings" element={<Settings />} />
</Routes>
# Next.js (App Router) — file structure
# src/app/page.tsx → /
# src/app/projects/page.tsx → /projects
# src/app/projects/[id]/page.tsx → /projects/:id
# src/app/settings/page.tsx → /settings
Each page.tsx file exports a default React component. Dynamic segments use bracket notation: [id] replaces :id. Nested layouts are defined with layout.tsx files that wrap child routes — replacing CRA's pattern of wrapping routes in layout components manually. The key benefit is that this structure is enforced by the framework, not by convention. New team members see the URL structure in the file tree without reading routing configuration.
For pages that use URL search parameters (filters, pagination), Next.js provides the useSearchParams hook in client components and direct access to searchParams in server components, replacing react-router's useSearchParams.
Dynamic segments use bracket notation: [id] replaces :id.
Phase 3: Data Fetching Patterns
This is where the biggest conceptual shift happens. In CRA, all data fetching happens on the client via useEffect or React Query. In Next.js, the default is server-side data fetching — your component fetches data on the server and renders with it, sending fully-formed HTML to the client.
# CRA pattern — client-side fetching
# src/pages/ProjectDetail.tsx
function ProjectDetail() {
const { id } = useParams();
const [project, setProject] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetch(`/api/projects/${id}`)
.then(res => res.json())
.then(data => { setProject(data); setLoading(false); });
}, [id]);
if (loading) return <Spinner />;
return <ProjectView project={project} />;
}
# Next.js pattern — server-side fetching
# src/app/projects/[id]/page.tsx
async function ProjectDetail({ params }: { params: { id: string } }) {
const project = await fetch(
`${process.env.API_URL}/projects/${params.id}`,
{ next: { revalidate: 60 } } // cache for 60 seconds
).then(res => res.json());
return <ProjectView project={project} />;
}
Notice the differences: no loading state management, no useEffect, no client-side spinner. The page renders on the server with data already available. The user never sees a loading skeleton — they see the complete page immediately. For data that needs to be interactive or update in real-time, you can still use client components with React Query or SWR, but most read-heavy pages benefit from server-side fetching.
Phase 4: Handling CSS Modules and Styles
CRA supports CSS Modules, plain CSS, and Sass out of the box. Next.js supports all of these plus CSS-in-JS libraries and Tailwind CSS. If your CRA app uses CSS Modules, they migrate directly — just move the .module.css files alongside their components.
If you are using a CSS-in-JS library like styled-components or emotion, you need to configure it for server-side rendering. Without SSR support, your pages will flash unstyled content (FOUC) on initial load because the styles are generated by JavaScript that has not yet executed.
# For styled-components, add to next.config.js:
module.exports = {
compiler: {
styledComponents: true,
},
};
Consider this migration as an opportunity to simplify your styling approach. If you are using multiple styling methods (CSS Modules in some components, styled-components in others, inline styles in a few more), consolidate to a single approach. Tailwind CSS is the most popular choice for Next.js projects because it works identically on server and client components without any SSR configuration.
Want expert help with this? Let's make it happen.
Get a Free ConsultationPhase 5: Environment Variables
CRA exposes environment variables prefixed with REACT_APP_ and embeds them into the client bundle at build time. Next.js uses a different convention: variables prefixed with NEXT_PUBLIC_ are exposed to the client, while unprefixed variables are server-only. This distinction is a security improvement — API keys and secrets in unprefixed variables are never sent to the browser.
# CRA .env
REACT_APP_API_URL=https://api.example.com
REACT_APP_STRIPE_KEY=pk_live_xxx
# Next.js .env
# Server-only (never reaches browser)
API_URL=https://api.example.com
STRIPE_SECRET_KEY=sk_live_xxx
# Client-exposed
NEXT_PUBLIC_STRIPE_KEY=pk_live_xxx
Audit every REACT_APP_ variable and decide whether it truly needs client exposure. API URLs used in server components should be server-only. Secret keys should never have been in REACT_APP_ variables in the first place, and this migration is a good time to fix that security issue.
Phase 6: CI/CD Pipeline Updates
Your CI pipeline needs updates for Next.js's build process. The build command changes from react-scripts build to next build, and the output is a .next directory instead of a build directory. If you deploy to a static host, you can use next export for static generation, but most applications benefit from server-side rendering which requires a Node.js runtime.
# GitHub Actions workflow
- name: Build
run: npm run build
env:
API_URL: ${{ secrets.API_URL }}
# Dockerfile for server deployment
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine AS runner
WORKDIR /app
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/package*.json ./
RUN npm ci --production
EXPOSE 3000
CMD ["npm", "start"]
If your CRA app was deployed as static files behind a CDN, you will now need a Node.js server for SSR. Vercel, Netlify, and AWS Amplify all support Next.js natively. For self-hosted deployments, a Docker container behind nginx is the standard approach.
Phase 7: Testing Strategy
Your existing Jest unit tests for utility functions and pure components migrate directly. Component tests that rely on react-router's test utilities need updating to use Next.js's test helpers. Integration tests that test page rendering should use Playwright or Cypress, as they handle SSR and client hydration correctly.
# Replace react-router test wrapper
# Before (CRA):
render(<MemoryRouter><ProjectDetail /></MemoryRouter>);
# After (Next.js): test the page component directly
# Server components can be tested as async functions
const result = await ProjectDetail({ params: { id: "123" } });
expect(result).toBeTruthy();
Server components are simpler to test than client components because they are just async functions that return JSX. No mocking useEffect, no faking API responses with MSW — you mock the fetch call and assert the rendered output. This often reduces test complexity by 30-40%.
Before and After Metrics
Across five CRA-to-Next.js migrations we have completed, the average improvements are:
| Metric | CRA | Next.js | Improvement |
|---|---|---|---|
| Largest Contentful Paint | 3.4s | 1.1s | 68% faster |
| First Contentful Paint | 2.1s | 0.6s | 71% faster |
| JavaScript bundle size | 420KB | 180KB | 57% smaller |
| Time to Interactive | 4.2s | 1.8s | 57% faster |
| Lighthouse Performance | 62 | 94 | +32 points |
| Build time (CI) | 90s | 45s | 50% faster |
The bundle size reduction comes from server components eliminating client-side code for data fetching, server-rendered initial HTML reducing the JavaScript needed for first paint, and automatic code splitting at the route level instead of CRA's single-bundle approach.
Common Migration Pitfalls
Avoid these mistakes that cause the most friction during migration. First, do not mark everything as a client component with "use client" — this defeats the purpose of server components and negates the performance benefits. Start with server components as the default and only add "use client" when a component needs browser APIs, event handlers, or state. Second, do not migrate all pages at once. Move one route at a time, deploy it, and verify it works in production before moving the next. Third, watch out for libraries that use browser-only APIs (window, document, localStorage) at module scope — these crash during server-side rendering. Wrap them in dynamic imports with { ssr: false } or guard them with typeof window checks. If your project involves a Django backend communicating with a Next.js frontend, our Django development service handles this architecture regularly.
Related reading: React vs Django Templates: When to Add a JavaScript Frontend · Building a Tenant Portal: Architecture Decisions That Matter · Modernizing Legacy Django: From 2.x to 6.1 Without a Rewrite
Frequently asked questions
How much does a custom website cost in 2027?
A marketing website with 5-10 pages costs $3,000-10,000. A custom web application with user accounts, database, and business logic costs $15,000-75,000. A complex platform (SaaS, marketplace, portal) costs $50,000-200,000+. Price depends on features, design complexity, and integration requirements.
How long does it take to build a custom website?
A marketing site: 2-4 weeks. A web application MVP: 6-12 weeks. A complex platform: 3-6 months. These timelines assume one developer working full-time. Add 50% for part-time engagement. The longest phases are usually design approval and content creation, not development.
Should I use a website builder or hire a developer?
Website builders (Squarespace, Wix) work for simple marketing sites. Hire a developer when you need: custom functionality, database-driven features, integrations with business systems, or performance and SEO control that builders cannot provide. The break-even point is usually when you need more than a contact form and a blog.
Desarrollador full-stack especializado en Django, automatización con IA y gestión de Google Ads. Construyo plataformas SaaS de producción y aplicaciones web personalizadas para empresas en todo EE.UU.