DEV Community

Usama
Usama

Posted on

Fixing White Screen in React + Netlify: “Unexpected token <” Error Solved

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 '<'
Enter fullscreen mode Exit fullscreen mode

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 ✅

  1. Check build settings on Netlify
  • Build command → npm run build
  • Publish directory → build
  1. Add _redirects file inside public/ folder Create a file named _redirects (no extension) with this content:
   /*    /index.html   200
Enter fullscreen mode Exit fullscreen mode
  1. Clear cache & redeploy
    In Netlify → Deploys tab → “Clear cache and redeploy”.

  2. Test production build locally

   npm run build
   npx serve -s build
Enter fullscreen mode Exit fullscreen mode

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)