-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should handle when app server is reloaded via nodemon #21
Comments
Using nodemon with webpack dev builds will always cause this, because nodemon does a hard exit which shuts down the process forcibly. I don't recommend restarting the whole process like this, as you'll lose the webpack in-memory cache and the next build will take much longer. |
You should at least configure nodemon to ignore the The client-side event-stream should reconnect after the server has restarted. Feel free to reopen if you have more questions or suggestions. |
I've expanded my sample application to show a way of reloading express routes without restarting the whole process: |
@glenjamin Yeah... that makes sense. That repo is so helpful. I'm going to have to mess with my environment for the fifth (!!) time but this is really great, thanks so much. |
Hello @glenjamin, I was wondering if it is possible to prevent Thank you for the help! |
It's not possible, as nodemon restarts the whole process, so you lose anything webpack was remembering. You might be able to get some speed ups after a restart from configuring webpack to cache it's files on disk instead of in memory, but I've never tried this. My preferred way to handle server code reloading is as shown in the ultimate example: keep the server running, and reload the root route handler |
Hi @glenjamin, I am reading your application: https://github.com/glenjamin/ultimate-hot-reloading-example , it's awesome! Thanks a lot if can get your help! |
Correct, the key point is here: https://github.com/glenjamin/ultimate-hot-reloading-example/blob/master/server.js#L28 Whenever the |
If anyone has time and interest, I could use help troubleshooting an adaptation of this lesson in my project (reference only the mongo-deploy-react-hot branch). Basically, when react components are modified, the hot reload works as expected, but whenever non-react files are changed, the same error appears:
Here is a link to the project's express server, where I believe the problems lie. |
That error means the server has ended the connection. It could be avoided if we did a clean shutdown of the event source connection, but I don't think it's important. Continuing hot reloading after a server restart is trickier, I think it might work if you configure Dev middleware to write to disk instead of memory, but that is outside the scope of this module |
i guess maybe the lesson is to not use |
It's probably possible, but not something I've tried - I use the strategies demonstrated in the "ultimate hot reloading example" linked above. |
Here is the solution to this: run webpack middle ware on a seperate express server. You can then restart your main express server without re executing the middleware/compiler. here is a gist https://gist.github.com/ezekielchentnik/ed0cabb09bf29e5b4a7a461a11b1c63d - I also use piping instead of nodemon. all works like a charm |
@glenjamin I built It's also a slightly different approach to your ultimate hot reloading example (it won't hot reload non-bundle assets like express routes for example) but I've found it to work really nicely along side |
I have it so that my app server (which, of course, contains webpack-dev-middleware and webpack-hot-middleware) is restarted when any server-side files are changed. Unfortunately, what's happening is that as soon as the server is restarted, something is triggered such that now I see the following message in the browser console:
I don't know enough to know why this is happening exactly, but I do know that I'd like the page to reload when this happens. Any idea on how to do this?
The text was updated successfully, but these errors were encountered: