16

I'm trying to build an app using Laravel 9 and ReactJS with vite js. I tried following command to build.

npm run dev

But I'm getting following errors,

GET http://[::1]:5173/resources/css/app.css net::ERR_CONNECTION_REFUSED

GET http://[::1]:5173/@vite/client net::ERR_CONNECTION_REFUSED

GET http://[::1]:5173/resources/js/app.jsx net::ERR_CONNECTION_REFUSED

GET http://[::1]:5173/@react-refresh net::ERR_CONNECTION_REFUSED

miken32
  • 42,008
  • 16
  • 111
  • 154
Sourav Das
  • 527
  • 2
  • 5
  • 13

8 Answers8

33

If you entered npm run build on production, your .env file looks good, and you still have such errors as the author – just delete the file public/hot.

miken32
  • 42,008
  • 16
  • 111
  • 154
Paweł Moskal
  • 613
  • 7
  • 10
5

For those using Laravel Sail, open the vite.config.js file and configure it like so:

export default defineConfig({

  plugins: [
    react(),
    laravel({
        input: ['resources/css/app.css', 'resources/js/app.js'],
        refresh: true,
    }),
  ], 
  server: {
    hmr: {
        host: 'localhost',
    },
  }
});

If need be, stop and restart the server sail npm run dev

BlackPearl
  • 2,532
  • 3
  • 33
  • 49
1

This means that your assets are not built yet, use npm run build.

Majd Harb
  • 41
  • 4
1

Its Work for me 1-First Run npm run dev in Terminal 2-Then Run npm run build

javad asghari
  • 69
  • 1
  • 2
0

I think I may have found a solution with the build option called Rollup. When building in production, rollup will remove unused code. In this process it will bundle the required assets and reference them in accordance to the URL that you would be using at that current moment.

To fixed it, you could try this:

export default defineConfig({
      build: {
        rollupOptions: {}
      }
    })

I was helped by a similar issue posted on Github so maybe you could use that as a point of reference. Here is the Discussion

KingStevenNOS
  • 119
  • 1
  • 4
0

add host in your vite.config.js, so it will force it to IPv4

export default defineConfig({
    server: {
        host: '127.0.0.1',  // Add this to force IPv4 only
    },
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
    ],
});
Kidd Tang
  • 1,821
  • 1
  • 14
  • 17
0

In my case the issue was that the port 5173 was already in use. I've just freed it - and everything worked again. Hope that helps.

runner
  • 9
  • 1
0

If you have run npm run dev then you must find a file in public/hot and Rewrite the proper address / URL in it. For me http://127.0.0.1:5173 worked.

Jay Momaya
  • 1,831
  • 19
  • 32