fix(cjs): fix HMR issue with mongoose - #7938
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #7938 +/- ##
==========================================
- Coverage 68.92% 68.91% -0.02%
==========================================
Files 91 91
Lines 3846 3847 +1
Branches 1041 1042 +1
==========================================
Hits 2651 2651
Misses 971 971
- Partials 224 225 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
| import { join } from 'path' | ||
|
|
||
| export function isHMRCompatible (id) { | ||
| return !/[/\\]mongoose[/\\/](lib[/\\/])?index.js/.test(id) |
There was a problem hiding this comment.
Why not marking entire mongoose dep as incompatible? A regex matching node_modules/mongoose as a part of id
There was a problem hiding this comment.
mongoose has lots of files and it does not bundle them. clearing entire mongose deps causes Maximum call stack size exceeded. (Honestly, I don't understand why)
There was a problem hiding this comment.
Do you have a repo to quickly check? Maybe it is a nuxt HMR bug
There was a problem hiding this comment.
I'll have one, let me push it to github
There was a problem hiding this comment.
There was a problem hiding this comment.
Can we create a nuxt module for mongoouse and clear cache via watchers or modules:before hook ?
There was a problem hiding this comment.
@clarkdo Seems nice idea. Also there is an alternative way i used once to use unload method.
Since it is really minor case (serverMiddleware + HMR + mongoose) but not uncommon setup, it may worth excluding mongoose by default. Nuxt 3 will isolate functions anyway so we won't have such issues for HMR.
Types of changes
Description
Introduce
isHMRCompatiblefunction to detect clear incompatible modules cache.As we know
mongooseis incompatible and clearingmongoose/index.jsandmongoose/lib/index.jsmakes it work.close #7917
Checklist: