Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve 404 error in a deployed react- vite app?

I have a production-ready React app built with vite. I have run the build process and uploaded the contents of the dist file within the subdirectory it is supposed to be in. When i visit the URL it throws a 404 error in the console. Failed to load resource: the server responded with a status of 404 (Not Found) - index-77febc61.js:1 for my index.js file. I have checked the index.html file to ensure the src tag is pointing to the right js file and it seems fine.

The URL to the site should be https://mydomainname.com/susbcriber. All the files are uploaded in the subscriber directory but on visiting the site it shows a white screen with the 404 error.

Any help on how i could resolve this is greatly appreciated.

like image 571
Nate Avatar asked Oct 12 '25 11:10

Nate


2 Answers

You should create a vercel.json file in the root directory and put this code inside it

    {
    "routes":[
        {
            "src":"/[^.]+",
            "dest":"/"
        }
    ]
    }

I guarantee it will work

like image 84
mimo Avatar answered Oct 14 '25 09:10

mimo


There are some solutions, for me was the .htaccess

I put this in my .htaccess file

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

And this in my vite.config.ts

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  base: '/',
})
like image 21
Roel Leal Avatar answered Oct 14 '25 08:10

Roel Leal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!