When I deployed my React app on Netlify, everything worked fine in local build (npm start
, npm run build
).
But on production deploy, the site showed only a white screen.
In the console, I saw this error:
Uncaught SyntaxError: Unexpected token '<'
What this error means
This usually happens when Netlify serves index.html
instead of the JS bundle.
React apps are SPAs (single page applications), and without proper redirects, Netlify gets confused.
The Fix ✅
- Check build settings on Netlify
- Build command →
npm run build
- Publish directory →
build
-
Add
_redirects
file insidepublic/
folder Create a file named_redirects
(no extension) with this content:
/* /index.html 200
Clear cache & redeploy
In Netlify → Deploys tab → “Clear cache and redeploy”.Test production build locally
npm run build
npx serve -s build
If this works locally, your code is fine.
Bonus Tip
In my case, even after clearing cache the white screen stayed.
When I created a fresh new deploy from scratch, everything started working.
So if nothing works:
👉 Delete the old site in Netlify → create a new one → link GitHub repo → deploy.
Conclusion
This bug wasted me hours 😅, but the lesson is:
- Always add
_redirects
file - Always test production build locally
- If all else fails → redeploy fresh
Hopefully this helps someone save time! 🚀
Top comments (0)