Laravel Sail page cannot load assets from the Vite dev server on port 5173
The page loads without its CSS and JavaScript while the app itself answersShort answer
In Sail the Vite dev server runs inside the container and the browser reaches it through a published port. Assets fail when npm run dev is not running in the container, when compose.yaml does not publish the Vite port or it differs from VITE_PORT, when public/hot holds the wrong host, or when a stale hot file outlives the server.
Fix it fast
1Find out which cause you have
Read the hot file inside the container, then ask the dev server from your own machine whether it answers on the published port. A refused connection points at the first or second cause; a wrong address in the file points at the third or fourth.
sail shell cat public/hot exit curl -I http://localhost:5173/@vite/client2Match what you see, then jump to its fix
- 1
public/hot is missing, or it exists and nothing answers on port 5173The dev server is not running inside the containerFix - 2
The dev server prints its Local line, yet the browser cannot connect to localhost:5173The Vite port is not published, or differs from VITE_PORTFix - 3
public/hot shows an address other than http://localhost:5173, for example http://0.0.0.0:5173public/hot holds a host the browser does not useFix - 4
public/hot exists, no dev server is running, and the page still asks for dev server URLsA stale hot file outlived the dev serverFix
- 1
What does the error look like?
The page loads without its CSS and JavaScript while the app itself answersRequests for /@vite/client and your entry files fail in the browser network tab
Cause 1 of 4
The dev server is not running inside the container
1Check
Sail runs the app in a container, so Node and npm commands go through Sail as well. The Laravel plugin applies its Sail host and port rules only when the LARAVEL_SAIL variable is set, and Sail sets it inside the container. The process also has to stay running in its own terminal.
sail shell
ls -l public/hot2Fix
Install the packages and start the dev server through Sail, and leave that terminal open while you work.
sail npm install
sail npm run dev3Verify
The terminal prints a Local line for port 5173, and public/hot now holds http://localhost:5173.
sail shell
cat public/hotConfirmed by laravel.com
Cause 2 of 4
The Vite port is not published, or differs from VITE_PORT
1Check
Sail publishes the Vite port in compose.yaml through VITE_PORT, default 5173. Under Sail the Laravel plugin starts Vite on that same port, unless server.port is set in vite.config.js, and it exits instead of moving to another port. A compose.yaml without the ports line, or a server.port that differs from the published one, leaves the browser with nothing to connect to.
grep -n "VITE_PORT" compose.yaml .env
grep -n "port" vite.config.js2Fix
Make sure the service has the ports line below, remove server.port from vite.config.js, and set VITE_PORT in .env only if you want a different port. Then recreate the containers.
# compose.yaml, service laravel.test
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
# .env (only for a different port)
VITE_PORT=5174
# then
sail up -d3Verify
With the dev server running, the published port answers from your own machine.
curl -I http://localhost:5173/@vite/clientConfirmed by raw.githubusercontent.com
Cause 3 of 4
public/hot holds a host the browser does not use
1Check
Under Sail the plugin binds Vite to 0.0.0.0 and writes localhost into the hot file. If you set server.host yourself, that value is written as it is, and 0.0.0.0 is a bind address, not an address to browse. On WSL2 the Laravel docs also ask for hmr.host to be localhost.
grep -n "host" vite.config.js
sail shell
cat public/hot2Fix
Remove the explicit server.host, or add hmr.host set to localhost, which the plugin prefers when it writes the hot file.
// vite.config.js
export default defineConfig({
// plugins ...
server: {
hmr: {
host: 'localhost',
},
},
});3Verify
Restart sail npm run dev. The hot file must show http://localhost:5173.
sail shell
cat public/hotConfirmed by laravel.com
Cause 4 of 4
A stale hot file outlived the dev server
1Check
The @vite directive treats the existence of public/hot as "the dev server is running" and loads every asset from the address inside it. The plugin deletes the file when the process exits normally or receives SIGINT, SIGTERM or SIGHUP, and nothing else deletes it. A process that dies another way can leave it behind.
sail shell
ls -l public/hot2Fix
Delete the file, or start the dev server again, which rewrites it. For a build without a dev server, remove the file and build the assets, then @vite loads the built files.
sail shell
rm public/hot
exit
sail npm run build3Verify
Reload the page. Assets now load from the build folder, or from the fresh dev server.
curl -I http://localhostConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Start the dev server only through sail npm run dev, and stop it with Ctrl+C so that the hot file is removed.
- Keep VITE_PORT in .env as the one place that decides the port, and leave server.port out of vite.config.js.
- After you edit the ports in compose.yaml, run sail up -d so that Docker Compose recreates the container.
- Do not set server.host under Sail unless you also set hmr.host.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
- EZ EstimaterConstruction quoting and job tracking for contractors, on a Laravel and Firebase stack.
Related fixes
Back end
Laravel says Vite manifest not found at public/build/manifest.json
Vite manifest not found at: /var/www/app/public/build/manifest.json
Laravel's @vite directive looks for a running dev server first, then for a built manifest file.
3 causes, each with a fixBack end
Laravel Sail pages take seconds to load on Windows with WSL2
pwd prints a path that starts with /mnt/c
On Windows, Laravel Sail is slow when the project lives on the Windows drive (under /mnt/c) and Docker bind-mounts it into the container.
3 causes, each with a fixBack end
Browser does not reload when I save a Blade file under Vite
CSS and JavaScript hot update, but view changes need a manual refresh
Vite only reloads the page for Blade files when the Laravel plugin's refresh option is on.
3 causes, each with a fixBack end
Livewire's JavaScript file returns 404 and components do nothing
Livewire components render but wire:click and wire:model do nothing
Livewire serves its JavaScript through a Laravel route, so a 404 means the request never reached that route.
3 causes, each with a fixBack end
The AWS SDK in Node.js cannot find any credentials
Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
The AWS SDK walks a fixed credential chain: code, environment variables, the shared files in ~/.aws, then role sources such as ECS or EC2.
3 causes, each with a fixBack end
AWS SDK for JavaScript v3 cannot find credentials, even for DynamoDB Local
A DynamoDB client pointed at http://localhost:8000 fails with the same message
The SDK walked its default credential provider chain and found nothing.
3 causes, each with a fix