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

seedphrase's avatar

Vite and valet PHP 8.1.8 and LARAVEL 9.27

Hi! I had a problem with vite and valet, when I changed my vite.config.js file and followed the code of Freek.dev Making Vite and Valet play nice together https://freek.dev/2276-making-vite-and-valet-play-nice-together I got cors error Blocking a cross-origin request: the “Same Origin” policy does not allow consulting the remote resource located at https://project.laravel.test:5173/@vite/client. and no style in my login page

0 likes
26 replies
Sinnbeck's avatar

Can you show the complete error? It should mention both domains

What url are you running laravel on?

seedphrase's avatar

Blocking of a multi-origin request (Cross-Origin Request): the “Same Origin” policy does not allow viewing of the remote resource located at https://project.laravel.test:5173/@vite/client. Reason: CORS request failed. Status code: (null). I used valet secure and I am in local env

Sinnbeck's avatar

@$omar what exact url do you visit when developing?

Sinnbeck's avatar

@0mar that's a hostname. The full url? :) is it perhaps http instead of https?

Sinnbeck's avatar

@0mar no worries. If it was solved, you can close the thread by marking a best answer

Sinnbeck's avatar

@0mar so you are typing the full error message instead of copy pasting it?

seedphrase's avatar

Yes it's the full error. When I change my vite.config.js without free.dev code I got this error : [vite] failed to connect to websocket. your current setup: (browser) 127.0.0.1:5173/ <--[HTTP]--> 127.0.0.1:(5173/ (server) (browser) 127.0.0.1:5173/ <--[WebSocket (failing)]--> 127.0.0.1:5173/ (server) Check out your Vite / network configuration and https://vitejs.dev/config/server-options.html#server-hmr .

Sinnbeck's avatar

@0mar But you manually typed it? If not, how could the domain be misspelled? Can you use the "valet guide" and then paste the actual error, instead of typing it

1 like
seedphrase's avatar

Firefox cannot establish a connection to the server at wss://127.0.0.1:5173/.

[vite] failed to connect to websocket.

your current setup: (browser) 127.0.0.1:5173/ <--[HTTP]--> 127.0.0.1:5173/ (server) (browser) 127.0.0.1:5173/ <--[WebSocket (failing)]--> 127.0.0.1:5173/ (server) Check out your Vite / network configuration and https://vitejs.dev/config/server-options.html#server-hmr .

socket client.ts:48
setupWebSocket client.ts:99
(Async: EventListener.handleEvent)
setupWebSocket client.ts:95
fallback client.ts:43
setupWebSocket client.ts:99
seedphrase's avatar

import fs from 'fs';

import { defineConfig } from 'vite';

import laravel from 'laravel-vite-plugin';

import vue from '@vitejs/plugin-vue';

import {homedir} from 'os'

import {resolve} from 'path'

let host = 'project.laravel.test'

export default defineConfig({

plugins: [

    laravel({

        input: [

            'resources/css/app.css',

            'resources/js/app.js',

        ],

        refresh: true,

    }),

    vue({

        template: {

            transformAssetUrls: {

                base: null,

                includeAbsolute: false,

            },

        },

    }),

],

server: detectServerConfig(host),

});

function detectServerConfig(host) {

let keyPath = resolve(homedir(), `.config/valet/Certificates/${host}.key`)

let certificatePath = resolve(homedir(), `.config/valet/Certificates/${host}.crt`)


if (!fs.existsSync(keyPath)) {

    return {}
}

if (!fs.existsSync(certificatePath)) {
    return {}
}

return {
    hmr: {host},
    host,
    https: {
        key: fs.readFileSync(keyPath),
        cert: fs.readFileSync(certificatePath),
    },
}

}

Sinnbeck's avatar

@0mar good. And if start vite now you get the websocket error with 127.0.0.1?

seedphrase's avatar

@Sinnbeck Yes https I don't have this problem when I run valet unsecure project.laravel.test and then run it on http

Sinnbeck's avatar

@0mar ok then I'm unsure. Maybe another Mac user with valet has a solution

seedphrase's avatar

It was the same when I added

server: { 

    https: true, 

    host: 'project.laravel.test', 

},  

before I found freek.dev code

Please or to participate in this conversation.