Skip to content

Black Friday: up to 50% off.

Cloudzyro
How-to

How to deploy a React app (Vite, Create React App or Next.js)

Kofi Agyem

, Founder and CEO, CloudzyroPublished · 6 min read

On this page
  1. 1. The short answer
  2. 2. Step 1: work out which kind of React app you have
  3. 3. Step 2: test the production build on your computer
  4. 4. Step 3: set your environment variables
  5. 5. Step 4: make routes work on refresh
  6. 6. Step 5: check the base path
  7. 7. Step 6: deploy it
  8. 8. Step 7: connect your domain and your backend
  9. 9. When it goes wrong
  10. 10. Sources

How to deploy a React app: work out which kind you have, test the production build, set VITE_ variables, make routes work on refresh, then put it online.

1. The short answer

To deploy a React app, run `npm run build` to turn it into static files, check them with a local preview, put your public settings in `VITE_` environment variables, and host the output folder somewhere that sends every route to `index.html`. If your app renders on the server (Next.js or Remix), it needs a Node.js host instead. Most React apps can be hosted free.

Hosting specifics for React on Cloudzyro are on our React hosting page. This guide is the how-to, whichever host you choose.

2. Step 1: work out which kind of React app you have

Look at your package.json:

  • `vite` in the dependencies: a single-page app built with Vite. Most React apps made today are, including those from Lovable and Bolt. The build writes static files to dist.
  • `react-scripts`: Create React App. It builds to build. The React team deprecated it in February 2025, but existing apps still build and deploy fine.
  • `next`: Next.js. If it renders pages on the server or has API routes, it needs a Node.js server; see how to deploy a Next.js app. With output: "export" it's static files in out.
  • Something else (webpack or Parcel on their own): build it locally and deploy the output folder as a static site.

The rest of this guide is about the first two, which are by far the most common.

3. Step 2: test the production build on your computer

The development server hides problems the production build shows. Run the real build and preview it before you deploy:

npm install
npm run build
npm run preview   # Vite: serves dist at http://localhost:4173

For Create React App, serve the build folder with any static server, such as npx serve -s build. Click through every page, refresh on a page that isn't the home page, and open the browser console for errors. If the build fails here, it'll fail on the host too, so fix it first: TypeScript errors and imports whose capitalization doesn't match the file name are the usual culprits (Macs forgive the second; Linux servers don't).

4. Step 3: set your environment variables

Vite only exposes variables that start with VITE_ to your app, read with import.meta.env.VITE_NAME. Create React App uses REACT_APP_ and process.env. Both are baked into the JavaScript when the app is built, which means two things:

  • Set them on your host before you build, and deploy again whenever one changes.
  • Every visitor can read them. A Supabase URL and anon key, or a Stripe publishable key, are fine. A secret key never is: it belongs on a server, in an API route or in your database's rules.

On Cloudzyro, add them on the site's Environment variables tab. More on why the difference matters: environment variables explained.

5. Step 4: make routes work on refresh

With React Router, addresses such as /pricing exist only inside your JavaScript. Click a link and it works; refresh, or open a shared link, and the server looks for a file called pricing, finds none and returns a 404. The fix is a rule on the host: any address that isn't a real file gets index.html, and your router takes it from there.

Cloudzyro serves Vite and Create React App projects this way already, so there's nothing to add. On other hosts, look for a setting called rewrites, redirects or single-page app mode. If you can't change the server at all, a hash router (addresses like /#/pricing) works anywhere, which is what our Admin dashboard template uses.

6. Step 5: check the base path

A React app at the root of a domain, such as app.example.com, needs a base path of /, which is the default. An app served from a subfolder, such as GitHub Pages' username.github.io/repo/, needs base: "/repo/" in vite.config (or homepage in package.json for Create React App).

A wrong base path gives the classic blank page: the HTML loads, but the browser asks for JavaScript at the wrong address. The browser console's network errors show exactly which file it couldn't find.

7. Step 6: deploy it

On Cloudzyro, any of these works. We detect Vite or react-scripts, run your build on Node 24 and serve the output as a single-page app:

  • From GitHub, GitLab or Bitbucket: connect the repository and branch, and each push deploys by itself. In a monorepo, set the folder, such as apps/web.
  • Upload: drop the project folder in the console. We leave out node_modules, dist, build and .env files and build it ourselves. Or upload an already-built folder with its index.html and it's served as it is.
  • From your AI tool: if Claude, Cursor, ChatGPT or Codex wrote the app, connect Cloudzyro and ask: “Put this React app online with Cloudzyro.”

It's live at yourname.cloudzyro.app on the free Launch plan, business use allowed, and a static React app never sleeps. Your built files are cached by Cloudflare close to visitors; index.html isn't, so a new version shows straight away.

Elsewhere, the steps are similar: connect the repository, set the build command to npm run build and the output folder to dist (Vite) or build (Create React App), and add the rewrite rule from step 4. Vite's own deployment guide, linked below, covers several hosts.

8. Step 7: connect your domain and your backend

Add your domain on the site's Domains tab and point www at domains.cloudzyro.app with a CNAME. Then add the new address to anything that checks where requests come from: Supabase's allowed redirect URLs for sign-in, and your API's allowed origins. If you skip this, sign-in breaks or the browser blocks API calls with a CORS error.

Need a backend? Connect Supabase for a database and sign-in without running a server, or deploy a separate Node.js or Express API.

9. When it goes wrong

  • Blank page: wrong base path (step 5), or a JavaScript error; check the browser console.
  • 404 on refresh: the host isn't sending unknown routes to index.html (step 4).
  • Variable is undefined: it doesn't start with VITE_, or it was added after the build. Deploy again.
  • Build fails on the host but not locally: a capitalization mismatch in an import, a missing lockfile, or a Node.js version your tools don't support. Pin one with engines.node or .nvmrc.
  • Asked for a start script: the host didn't recognize Vite or react-scripts and treated the app as a Node.js server. Build locally and upload the output folder, or move the project to Vite.

Starting a new React app instead? Our React templates are ready to deploy, or edit the Admin dashboard template with Cloudzyro Agent and describe what your app should show.

10. Sources

Checked on November 25, 2026.

Questions

How do I deploy a React app for free?
Build it into static files and host them on a free plan. On Cloudzyro, connect the GitHub repository, upload the project folder or ask your AI tool to deploy it; we run the build and serve the files at a free cloudzyro.app address, and a static React app never sleeps.
Why does my React app show a 404 when I refresh a page?
Your router changes the address in the browser, but there's no file at that address on the server. The host must send every unknown address to index.html. Cloudzyro does this for Vite and Create React App projects; other hosts need a rewrite rule.
Why is my deployed React app a blank page?
Usually the base path is wrong, so the browser can't find the JavaScript files. Check that Vite's base (or Create React App's homepage) matches where the app is served, which is / at the root of a domain. The browser console shows which file failed to load.
Do I need a server to deploy a React app?
No, unless you use server rendering. A React app built with Vite or Create React App is static files that run in the visitor's browser. Next.js and Remix apps with server rendering need a Node.js server.
Should I still use Create React App?
Not for new projects. The React team deprecated Create React App in February 2025. Existing apps still build and deploy; for new ones, use Vite or a framework such as Next.js.

Put your site online free

From your AI tool, Git or a zip, with every version kept.