4

Having built the assets,

build
vite build

vite v3.0.3 building for production...
✓ 64 modules transformed.
public/build/manifest.json             0.28 KiB
public/build/assets/app.45719a2b.css   189.82 KiB / gzip: 26.83 KiB
public/build/assets/app.bbc97e91.js    117.98 KiB / gzip: 37.68 KiB

in a newly created Laravel 9 project I am getting the console error messages

GET http://localhost:8001/public/build/assets/app.45719a2b.css net::ERR_ABORTED 404 (Not Found)
GET http://localhost:8001/public/build/assets/app.bbc97e91.js net::ERR_ABORTED 404 (Not Found)

Both are reported as being in the layout blade at a line containing

@vite('resources/js/app.js')

I have followed all the instructions, for getting this far that I could find, but to no avail, the same error occurs. I have reworked this project three times using the directions and it all comes to this error.

Howard1471
  • 43
  • 1
  • 6
  • I was having this issue when deploying to a server, managed to fix it by deleting everything on the server but the .env file and re-uploading – Ferares Aug 22 '22 at 11:42

3 Answers3

1

You need to set APP_URL environment variable, for correct working npm run build command. If your project works with local server tool (i.e. Valet, Homestead, Laragon, Wamp and etc), you need to add server section in your vite.config.js like this, for correct working npm run dev command:

import {defineConfig} from 'vite';
import laravel        from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/js/app.js',
                'resources/sass/app.scss'
            ],
            refresh: true,
        }),
    ],
    server: {
        https: false,
        host: 'yoursite.loc',
    },
});
Arm092
  • 580
  • 7
  • 12
1

Remove the vite "hot" file in /public folder. If that file is there, then it will run in development/staging mode and use the dev css/js files.

Just in case, I have added this to my production & stage server update script: rm ./public/hot

And added this to my .gitignore file: /public/hot

-1

I was able to resolve this by using the php artisan serve command, which basically means serving my website from laravel's built-in server. Initially I had used php -S 0.0.0.0:$PORT public/index.php which caused this issue.

MT_Shikomba
  • 129
  • 1
  • 6