laravel-mix
laravel-mix copied to clipboard
Laravel Mix HMR Server Does Not Launch
- Laravel Mix Version: 6.0.43 (
npm list --depth=0) - Node Version (
node -v): 16.13.1 - NPM Version (
npm -v): 8.1.2 - OS: Windows 10 21h2
Description:
THIS IS HAPPENING ON A FRESH NEW INSTALL OF LARAVEL AND MY OTHER PROJECTS
Running npm run hot changes the script tag sources to http://localhost:8080/*/*.* from http://localhost/*/*.* HOWEVER I always get net::ERR_EMPTY_RESPONSE from localhost:8080. The HMR server doesn't launch at all. The terminal output of the command also have no mention of spinning up a new web server.
PS C:\Users\Eric Wang\Documents\GitHub\test-laravel-mix> npm run hot
● Mix █████████████████████████ emitting (95%)
emit
● Mix █████████████████████████ done (99%) plugins
WebpackBar:done
✔ Mix
Compiled successfully in 5.51s
Laravel Mix v6.0.43
✔ Compiled Successfully in 5336ms
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬──────────┐├────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────┤│ css/app.css │ 47.6 KiB │└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────────┘webpack compiled successfully
Here's a picture of the browser failing to fetch the bundle files

Steps To Reproduce:
I am running Docker 4.5.1 using legacy Hyper-V. I containerized Laravel and PHP BUT not the frontend and JS. I am running Laravel Mix on my main system.
- Clone the fresh installation of Laravel from https://github.com/ericwang401/test-laravel-mix
- Clone Laradock in the project folder using
git clone https://github.com/laradock/laradock.git - CD to the Laradock folder and make
.envfile withcp .env.example .env - Inside
.envfile setPHP_VERSIONtoPHP_VERSION=8.0AND DO NOT EDIT MYSQL SETTINGS - Now edit the Laravel environment file
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=default
DB_USERNAME=default
DB_PASSWORD=secret
- Start up the Laravel app in
Laradockfolder usingdocker-compose up -d nginx mysql - Enter into bash mode in the Docker container
docker-compose exec workspace bash - Install Composer dependencies BUT NOT NPM DEPENDENCIES YET
composer i - Now exit out of the Docker container CNTRL + D
- Install NPM dependencies in project root ON YOUR MAIN SYSTEM
npm i - Run on your main system
npm run hot - Now go to
http://localhostand IT SHOULD be a white screen - Check console logs and it should give
net::ERR_EMPTY_RESPONSEwhen it tries to fetch the bundle files
REMEMBER: the backend is running inside Docker The frontend (Laravel Mix) is running on the host system
This issue is happening on a FRESH project installation of Laravel 9 + Jetstream AND it's also happening on my other older projects like https://github.com/StratumPanel/Stratum-Panel
The HMR server is simply not launching.
The HMR server is definitely launching for me here in your test project and I can load resources from it. I expect this is an interaction issue with Docker somehow. I'll need to investigate further.
The HMR server is definitely launching for me here in your test project and I can load resources from it. I expect this is an interaction issue with Docker somehow. I'll need to investigate further.
I found out the issue. The problem was that the default port, 8080, Laravel Mix HMR was using couldn't be binded to. Webpack Dev Server doesn't respond with a message of failing to bind to a port. To confirm this issue, I replicated the environment on my friend's PC and it too couldn't bind to port 8080, but this time it reported an error that the dev server couldn't bind to port 8080.
I fixed this issue by specifying
.options({
hmrOptions: {
host: 'localhost',
port: 4206
}
});
And it works! On both my friend's pc and my pc.
I used the exact same reproduction instructions on my friend's PC.
I spent way too long investigating this issue 😭
Could something be added to the documentation about this specific behavior? To warn the user that if they are receiving net::ERR_EMPTY_RESPONSE, they might need to change the port.
I'd like to figure out why you didn't see the message on your set up but your friends set up did. That's a bit weird. We should do something about that.
But yeah a note in the documentation is entirely reasonable.
I'd like to figure out why you didn't see the message on your set up but your friends set up did. That's a bit weird. We should do something about that.
But yeah a note in the documentation is entirely reasonable.
I opened a pull request with some edits at https://github.com/laravel-mix/laravel-mix/pull/3248
Please review it when it is convenient for you. Thank you!