vincent15000's avatar

Access to front with npm run dev

Hello,

I just open my computer from a friend's house, I execute php artisan serve and npm run dev and I don't have any styles.

I check the browser console and I see an error.

http://192.168.1.24:5173/resources/css/app.css net::ERR_ADDRESS_UNREACHABLE

At home, my computer has this address, but where I am now, my computer has another address.

I already cleared the cache and it doesn't work better.

What can I do to solve this problem ?

Thanks for your help.

V

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

The issue you're experiencing is likely due to the fact that Vite (which is used by Laravel Mix for development builds) is trying to serve your assets from a specific IP address that is no longer valid in your current network environment. This can happen when you move between different networks, as the local IP address of your machine changes.

To resolve this issue, you can configure Vite to use localhost instead of a specific IP address. Here's how you can do it:

  1. Update your vite.config.js file: Ensure that your Vite configuration is set to use localhost for the development server. You can do this by setting the host option in the server configuration.

    Open your vite.config.js file and modify it as follows:

    import { defineConfig } from 'vite';
    import laravel from 'laravel-vite-plugin';
    
    export default defineConfig({
        plugins: [
            laravel({
                input: ['resources/css/app.css', 'resources/js/app.js'],
                refresh: true,
            }),
        ],
        server: {
            host: 'localhost', // Use 'localhost' instead of a specific IP
            port: 5173, // Ensure this matches the port you're using
        },
    });
    
  2. Restart your development server: After making the changes, stop your current npm run dev process and start it again. This will ensure that Vite uses the updated configuration.

  3. Clear your browser cache: Sometimes, browsers cache the old IP address. Clear your browser cache or try accessing your application in an incognito window to ensure you're loading the latest assets.

By setting the host to localhost, you should be able to access your development server regardless of the network you're on, as localhost will always resolve to your local machine. If you need to access the server from other devices on the same network, you might need to adjust the host setting to 0.0.0.0 and access it via your machine's current IP address.

1 like

Please or to participate in this conversation.