π React Deployment Demystified: Solving Common Issues Across Platforms


Youβve built a shiny React appβ¦ now comes the real challenge β deployment.
Whether itβs deploying to Netlify, Vercel, GitHub Pages, Firebase Hosting, or custom servers, developers often face frustrating issues like:
β οΈ White screens after deployment
π Routes not working (404 errors)
π¦ Incorrect asset paths or broken images
π Environment variable misconfigurations
π CI/CD pipeline problems
Letβs walk through why these issues happen, how to solve them, and which platform fits your needs best.
π 1. React Deployment Basics: Understanding npm run build
Before deploying, always generate a production build:
npm run build
This creates an optimized build/
folder with minified JS, preprocessed HTML, and static assets β ready for the web!
π§ 2. Platform-Specific Challenges & Solutions
π΅ Netlify
Issue: App works locally but gives a blank screen or broken links after deploy.
β Solution:
- Add a
_redirects
file inpublic/
for SPA routing:
/* /index.html 200
Set build command: npm run build
Set publish directory: build/
π Bonus: Use netlify.toml
for advanced configs.
β« Vercel
Issue: Dynamic routes (React Router) result in 404s.
β Solution:
- Use
vercel.json
to define rewrites for SPA:
{
"rewrites": [
{ "source": "/(.*)", "destination": "/" }
]
}
- Vercel automatically detects React builds β minimal setup needed!
π₯ Firebase Hosting
Issue: Refreshing a routed page results in 404.
β Solution:
- Add
firebase.json
with rewrite rule:
{
"hosting": {
"public": "build",
"rewrites": [
{ "source": "**", "destination": "/index.html" }
]
}
}
- Use Firebase CLI:
firebase init
firebase deploy
π£ GitHub Pages
Issue: Routes break, and page reloads show 404.
β Solution:
- Set
"homepage"
field inpackage.json
:
"homepage": "https://yourusername.github.io/repo-name"
- Use
gh-pages
package:
npm install --save gh-pages
Add scripts:
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
}
π§± Custom Servers (Node, Nginx)
Issue: Routing and asset handling issues.
β Solution:
- On Nginx, add this config for SPA routing:
location / {
try_files $uri /index.html;
}
- On Node/Express, serve
index.html
for all unmatched routes:
app.use(express.static(path.join(__dirname, 'build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
π 3. Environment Variables in Production
Issue: Variables like API keys donβt work after deploy.
β Solution:
React only exposes env vars prefixed with
REACT_APP_
Define in
.env.production
and rebuild:
REACT_APP_API_URL=https://api.example.com
π 4. CI/CD Pipeline Tips
For teams using GitHub Actions, GitLab CI, or other pipelines:
β Checklist:
Run
npm install
andnpm run build
Cache dependencies for faster builds
Set correct environment and secrets
Use artifacts to upload the
build/
folder
π Bonus: Vite Deployment
Using Vite instead of Create React App?
Set base
in vite.config.js
:
export default defineConfig({
base: '/your-repo-name/',
});
Then build and deploy as usual.
π References
π§ Final Thoughts
Deployment is more than just uploading files β each platform has quirks that can break your app if you're not careful. But once you understand the rules of each system, deployment becomes a breeze.
π Follow Code Reacher for more in-depth React engineering guides, tool breakdowns, and real-world solutions.
Subscribe to my newsletter
Read articles from CodeReacher directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

CodeReacher
CodeReacher
Hi, I'm CodeReacher, a budding technical content writer with a passion for simplifying complex tech concepts. I come from a Computer Science background and love creating clear, engaging content around topics like Web development, DevOps, or cloud. I recently started Code Reacher, a blog dedicated to sharing practical, reference-rich tech articles for developers and learners. I'm eager to grow in the field and contribute meaningful content to the tech community.