taukuk's avatar

Laravel vite deployment not working

Hello,

I am deploying a website that I created with laravel 9 and vite. I run npm run build in my development server and then transfer the files over ftp to the production server, however, the @ vite directive doesn`t work and it links the files to 127.0.0.1:5173 and not the servers url. How can I fix this?

How I call the @ vite directive:

@viteReactRefresh
@vite(['resources/sass/app.scss', 'resources/js/index.tsx'])

How it renders in HTML

<script type="module" src="127.0.0.1:5173/@vite/client"></script>
<link rel="stylesheet" href="127.0.0.1:5173/resources/sass/app.scss" />
<script type="module" src="127.0.0.1:5173/resources/js/index.tsx">

The error I get on production:

GET 127.0.0.1:5173/resources/sass/app.scss net::ERR_CONNECTION_REFUSED

vite.config.js:

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

export default defineConfig({
    plugins: [
        react(),
        laravel({
            input: [
                'resources/sass/app.scss',
                'resources/js/index.tsx',
            ],
            refresh: true,
        }),
    ],
});
0 likes
13 replies
jlrdw's avatar

Seems as you have hard coded urls.

taukuk's avatar

@jlrdw The URLs are not hard coded. They should be automatically added by the @vite directive, but they point to localhost

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Sounds like you accidentally transfered the file hot in the public directory. Delete it and it should work

The file is used when running the dev server but will break production

33 likes
klim2020's avatar

@Sinnbeck Thank you bro, this is the best answer in the world, I came here from stackoverflow where they are trying to use {{ mix(.....) }} directive while compiling vite asset. :)

clinvest's avatar

@Sinnbeck haha each time there is a useful answer on a topic it's almost all the time you :) :) thank you!

macCésar's avatar

Hi @Sinnbeck

Just wanted to say a huge thanks for pointing out the issue with the hot file in the public directory. Deleting it totally fixed my production problem. You're a lifesaver!

Cheers!!

gauti544's avatar

Just Build Your Application By Running npm run build,it will created alias of app.js and app.css in public build folder rename it to app.js and app.css .And Export it any where you want nothing to change,any where.

1 like
saidhr20's avatar

You need to delete the hot from public : cd public && rm hot

6 likes

Please or to participate in this conversation.