Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lyleyboy's avatar

Vite and Valet

Hi folks,

I've recently started a new project which has come with Vite. I've never managed to get it to work properly.

When I run npm run dev I get a web socket issue.

client.ts:78 WebSocket connection to 'wss://127.0.0.1:5173/' failed: 
setupWebSocket @ client.ts:78
client.ts:78 

[vite] failed to connect to websocket.
your current setup:
  (browser) 127.0.0.1:5173/ <--[HTTP]--> localhost:5173/ (server)

This issue exists in Firefox and Chrome and it means I have to stop and start the NPM command every time I make a change, clearly not ideal.

I've been Googling around for a couple of days to try and find a solution but nothing seems to resolve the issue. I have added server details to the vite config file but every time I do this results in a CORS issue. I feel like the problem is that Vite doesn't see itself and the Valet secured dev site as the same server, hence the CORS issue.

My vite.config file is

import { defineConfig } from 'vite';
// import laravel from 'laravel-vite-plugin';
import laravel, { refreshPaths } from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
    plugins: [
        vue(),
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js',
            ],
            refresh: [
                // ...refreshPaths,
                // 'app/Http/**',
            ],
        }),


    ],

    // server: {
    //     https: true,
    //     hmr: {
    //         host: "comph.test",
    //         // protocol: "wss",
    //     },
    // },
});

I've purposely left comments in to show what I've tested.

Any pointers would be hugely appreciated!

0 likes
10 replies
lyleyboy's avatar

@Sinnbeck How in the world did all my Googleing now reveal this. I'll give it a go now, thanks.

lyleyboy's avatar

@Sinnbeck Hi, So that mostly worked. Vite is now able to connect etc and seems happy. When I now make a change in a .vue component file the browser reloads, the command prompt notes the page reload and the time stamp is updated, however, the page haven't been updated. I just changed a title and the old title remains. Any thoughts?

lyleyboy's avatar

@Sinnbeck Sorry I wasn't clear. The line in terminal

10:24:08 [vite] page reload resources/js/Components/SICGroupIndexComponent.vue
10:24:19 [vite] page reload resources/js/Components/SICGroupIndexComponent.vue (x2)
10:24:49 [vite] page reload resources/js/Components/SICGroupIndexComponent.vue (x3)
10:25:23 [vite] page reload resources/js/Components/SICGroupIndexComponent.vue (x4)
lyleyboy's avatar

No idea if it makes a difference but I'm loading Vue componenets like this

import('./bootstrap');
// import {createApp} from 'vue'
import {createApp} from 'vue/dist/vue.esm-bundler'
import '../css/app.css';

import SearchComponent from "@/Components/SearchComponent.vue";
const app = createApp(SearchComponent)
app.mount("#SearchComponent")

import MenuComponent from "@/Components/MenuComponent.vue";
const menuapp = createApp(MenuComponent)
menuapp.mount("#MenuComponent")

import SICGroupCreate from "@/Components/SICGroupCreateComponent.vue";
const siccreate = createApp(SICGroupCreate)
siccreate.mount("#SICGroupCreate")

import SICGroupindex from "@/Components/SICGroupindexComponent.vue";
const sicindex = createApp(SICGroupindex)
sicindex.mount("#SICGroupindex")

/**
 * CSS Imports
 */
import '../css/components/buttons.css';
Sinnbeck's avatar

@lyleyboy Sadly I dont use vue, so I cannot really say. But as vite is made by the same guy who made Vue I would assume it would work. Maybe make a test project with jetstream and compare it ? If it doesnt work there either, would be something else

wturrell's avatar

FWIW, as no-one else has mentioned, the single thing I needed to do to get auto refresh working on a static site was add this line - with correct domain substituted - to the laravel section of vite.config.js (this is now in the official docs if you look for it):

valetTls: 'mysite.test',
1 like

Please or to participate in this conversation.