Search code examples
http-status-code-404vite

Vite build gives 404


I am new to vite, I did install, wrote some code, did npm run dev and npm run build.

Everything went fine until uploading to my server.

index.html:

<script type="module" crossorigin src="/assets/index.a673cca3.js"></script>

Running from live server, I get these errors

Failed to load resource: net::ERR_FAILED index.4293b7ae.css:1
Failed to load resource: net::ERR_FILE_NOT_FOUND index.a673cca3.js

The filenames are correct and they are where are suposed to be.

What gives?


Solution

  • The problem is that all files on the public directory will resolve to the root. I was uploading to a directory (www. whatever.com/someproject/), so the solution was to specify the correct path on the vite.config.js

    // vite.config.js
    export default {
        base: '/someproject/'
    }
     
    // if uploading to a subdomain it is ok to no specify any dir:
    export default {
        base: '/'
    }
    
    // using a relative path will work on any dir:
    export default {
        base: './'
    }