Skip to content
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

Hot module replacement (HMR) not working with serverMiddleware dependencies #8976

Closed
rchl opened this issue Mar 11, 2021 · 6 comments
Closed

Comments

@rchl
Copy link

rchl commented Mar 11, 2021

Hot module replacement doesn't trigger when editing a file that is imported from server middleware.

Changing the server middleware file itself does trigger HMR for it but still doesn't reload imported modules.

Versions

  • nuxt: v2.15.3
  • node: v14

Reproduction

https://github.com/rchl/NuxtServerMiddlewareHMR

Steps to reproduce

  1. yarn dev
  2. Change either the test123 or 12345 values in api/server-middleware-util.js
  3. Reload the page

What is Expected?

The updated values are reflected on the page

What is actually happening?

The page keeps showing values before the change.

@pi0
Copy link
Member

pi0 commented Mar 11, 2021

Thanks for reproduction @rchl. I think issue is that, for HMR detection we depend on require.cache to create dependency graph (https://github.com/nuxt/nuxt.js/blob/f08f4efcde7bc174fd9b68a2a5a785d504659391/packages/utils/src/cjs.js#L47). Using jiti, we sync with require.cache for transpiled items but children is not being updated.

I will check to see if there is an easy fix. Otherwise we have to wait for nitro (or you can opt-in) since this method of HMR is unstable anyway...

@pi0 pi0 changed the title Hot module replacement (HMR) not working fully with server middleware Hot module replacement (HMR) not working with serverMiddleware dependencies Mar 11, 2021
@pi0
Copy link
Member

pi0 commented Mar 11, 2021

Fixed in jiti @ 1.6.4. You have to use yarn upgrade nuxt or recreate lockfile to get update.

@rchl
Copy link
Author

rchl commented Mar 11, 2021

Awesome. Thanks!

@wemod123
Copy link

wemod123 commented Jun 7, 2021

I confirmed on NUXT@2.15.6, NOT working.

I check the yarn.lock file, the jiti version is 1.9.2, Is this revert back?

@rchl
Copy link
Author

rchl commented Jun 7, 2021

It might be a different case. The issue I've reported is fixed. Feel free to report a new issue with more details.

(But I believe that CommonJS case still doesn't work. You have to use the ES Imports syntax for this to work.)

@wemod123
Copy link

wemod123 commented Jun 7, 2021

Good, I got the point, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants