Netlify throws 404 error on deploy for vite. Tried _redirect, tried adding netflify.toml. Nothing works

This issue is driving me nuts. In vite, my index.html file sits outside of the public folder by default. So I added a _redirects file to the public folder and also tried adding a netlify.toml file.

Neither works. Tried placing both in the root, both in public, one in public and one in root…



My netlify.toml file is :
command = “npm run build”
publish = “/build”
base =“/”

from = “/*”
to = “/index.html”
status = 200

And my _redirect is:
/* /index.html 200

Am I missing a step in the deployment process or something?

Extremely frustrating that netlify works fine with create react app but vite completely falls apart at deployment. Can someone help? Thanks

Do you have any data to back that up? Without determining this is a Netlify issue, I think it’s a little unfair to make such a statement. I use Vite and have used it since v1 and never had an issue.

In any case, you have not shared any info about the site, happy to check this further if you share some info.

Vite outputs in dist as far as I know, so that’s a potential problem.

I changed this to /dist and it did not resolve the issue.
command = “npm run build”
publish = “/dist”
base =“/”

from = “/*”
to = “/index.html”
status = 200

Deploy logs give me no errors and deploys fine.

What info do you need about the site?

Hi for one the site Id or site name would be helpful.


The site is
site ID e0ffef35-a7b9-40f7-8913-5695d4d5b887

A closer look at the logs reveals the issue:

You’re not building your site at all. Not sure where you have the netlify.toml you have mentioned, but you don’t have any build settings: Build & deploy | Site configuration | ubiquitous-klepon-d4ee71 | Netlify

Adding npm run build as the build command and setting dist as the directory should solve it.

Hi Hrishikesh,

I tried adding npm run build and dist to the configuration for deployment and now it fails to deploy


My netlify.toml is in the root


I’d suggest you to read your logs :slight_smile:

None of the problems you’ve faced so far have anything to do with Netlify, yet you called out Netlify being a problem in your first message. Your current problem is:

I think the problem is fairly self-explanatory, but if not it means your package.json doesn’t have any build command. Looking at the file structure you’ve shared, your files seem to be in the client folder, so maybe you need to set your base directory to client.

My package.json has build is:

“scripts”: {
“dev”: “vite”,
“build”: “vite build”,
“lint”: “eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0”,
“preview”: “vite preview”

Also tried setting my directory to client

The logs keep giving me the same build error.

Also tried making my package.json build command CI=“npm run build”

It would appear you haven’t followed @hrishikesh’s advice @learntocode

But looking at the screenshot above you set the package directory to client, not the base directory.

@learntocode The answer has been supplied by both @hrishikesh and @dig

If you read the definitions of those values in the documentation it reveals why it hasn’t worked for you:

The main issue being that your project is actually in the client folder.

You should only need to set the Base directory in the Netlify UI as client, at which point Netlify will find the netlify.toml file you have in that folder and proceed with the configuration in that file.

You would obviously need to make sure that configuration is also correct.

When I did exactly @hrishikesh and @dig suggested and it keeps telling me it can’t find the base directory. It will only find the base directory if I leave the netlify settings for base as “/” but modify the toml file only:

command = “vite build”
publish = “client/dist”
base = “client”

I tried with npm run build and it still wont’ find the build script so I changed my toml file and the netifly settings to vite build. It still cannot find the build script

In the UI you have have set the base directory as /, is that correct @learntocode?

And then the netlify.toml file is in client and in this file you have set the base as client?

So looking at the File-based configuration documentation I see

The netlify.toml is normally stored in the root of your site repository.

and then

All paths configured in the netlify.toml should be absolute paths relative to the base directory, which is the root by default (/).

It would appear you are not follow the documentation. As @nathanmartin explained, the solution to your issue is clearly outlined in previous posts and in the documentation.

Was able to resolve this by removing an extra folder layer below the root. Thanks everyone!

Awesome. Thanks for coming back and sharing your solution. Glad you got your site up and running! :+1:t6: