Search code examples
javascriptreactjsnpmnetlify

HTTP GET response 304 status error after deploying react app on netlify


  • I deployed react application in netlify
  • so I used npm run build command for building local scripts and manually deployed application in netlify for production mode
  • Build scripts are creating in local machine and uploaded in netlify site
  • It shows message as successful deployment
  • on clicking on URL link, previously shows status to GET request for build scripts as 404
  • After including redirects file in build folder, it changed for status to GET request for build scripts as 304 and showing error as

    syntax error: uncaught error : unexpected token <

  • For debugging, I commented files and run the code to find out the error
  • But, unable to find the root error
  • can you guys help me where I have done mistake with your suggestion
  • netlify URL link: https://lucid-shaw-bb2b3f.netlify.com
  • The application code is available in github and its link: https://github.com/aarivalagan/react-one
  • attached application screenshots below
  • providing code snippet below:

_redirects

/*     /index.html   200!

packagae.json

"scripts" : {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  }

enter image description here


Solution

  • If you are going to put a _redirects into your create react app, it should go into the public folder. The build folder should not be in your repository for continuous build solutions like Netlify.

    The _redirects you suggest here are typically used for when you use single page apps with a router like react router and want a path to always go to index.htmlwhen it does not exist. You would not want it to resolve asset value paths.

    This redirect rule will serve the index.html instead of giving a 404 no matter what URL the browser requests.

    _redirects

    /*    /index.html   200
    

    What is happening is you are forcing the index.html page to serve up even if there is not a valid path, which is happening with your assets.

    • Fix the original issue
    • Move the _redirects to public folder
    • remove the ! from the end of the redirects, so if a path is found it serves it correctly and not always forcing it to index.html