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

ServerMiddleware hot reload is faulty #9456

Closed
AregGhazaryan opened this issue Jun 19, 2021 · 9 comments
Closed

ServerMiddleware hot reload is faulty #9456

AregGhazaryan opened this issue Jun 19, 2021 · 9 comments

Comments

@AregGhazaryan
Copy link

Versions

  • nuxt: 2.15.3
  • node: 14.16.0

Reproduction

https://github.com/AregGhazaryan/nuxt-mongoose-server-middleware-reprod

Steps to reproduce

  1. npm i
  2. npm run dev
  3. go to /api/index.js and hit save
  4. voila error

What is Expected?

Server middleware should reload with latest changes without throwing errors.

What is actually happening?

The entire server middleware re-instantiates including, classes, functions and other resources. I can assure you that issue is not only mongoose related, because once i even had a telegram bot connected to my application which threw similar errors, like two instances are being run instead of just one.

@AregGhazaryan
Copy link
Author

Here's also the telegram bot error when saving server middleware

image

@stale
Copy link

stale bot commented Jul 21, 2021

Thanks for your contribution to Nuxt!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as pending will not be automatically marked as stale.

@stale stale bot added the stale label Jul 21, 2021
@AregGhazaryan
Copy link
Author

No, bad bot

@stale stale bot removed the stale label Jul 21, 2021
@Susccy
Copy link

Susccy commented Aug 3, 2021

I have the same problem currently and it makes developing a Mongoose backend very unpleasant. I have to manually exit and restart Nuxt everytime I make a change in any server file.
Neither the supposed fix in release v2.14.4 nor the workaround using require() suggested by @pi0 in #7917 solved it for me.

Copy link
Member

Atinux commented Aug 5, 2021

We are aware of this issue and it's not that easy to fix. We have a solution coming with the Nuxt Nitro module. will keep this issue updated.

@TomBell95
Copy link

Hi, I am now experiencing the same problem as mentioned by @Susccy & @AregGhazaryan - I have tried the workaround in #7917 which has not worked as well as upgrading to Nuxt 2.15.8.

@Susccy Did you manage to fix this? I am also having to manually refresh my Mongoose backend everytime.

Is there any update on this please? Thanks.

@Susccy
Copy link

Susccy commented Feb 24, 2022

@TomBell95 The following workaround makes hot reloading possible in my current mongoose project. Keep in mind you'll have to restart the app every time you make changes to the model.

// movie.model.js

import { Schema, models, model } from "mongoose"

const movieSchema = new Schema({
  // ...
})

// Try to use the existing model if it's been created before.
// Used to suppress a mongoose error on nuxt hot reload.
export default models.Movie || model("Movie", movieSchema)

@TomBell95
Copy link

@Susccy Brilliants, thanks.

@stale
Copy link

stale bot commented Apr 16, 2022

Thanks for your contribution to Nuxt!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as pending will not be automatically marked as stale.

@stale stale bot added the stale label Apr 16, 2022
@stale stale bot closed this as completed Apr 29, 2022
@danielroe danielroe added the 2.x label Jan 18, 2023
@danielroe danielroe mentioned this issue Jan 20, 2023
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

6 participants
@Atinux @danielroe @AregGhazaryan @TomBell95 @Susccy and others