-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Optimizing dependencies - Nuxt 3.8.1 #24196
Comments
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
Please don't write "Me too" or "Same issue here" - instead leave a 👍🏻 on the issue |
As far as I can tell, this dependency optimization will be triggered with any dynamically added component - particularly those introduced by third-party modules / plugins, or if you define a component using |
I think this has been resolved in a dependency (likely vite related). With the lockfile you provided it is reproducible, but if you refresh your lockfile I can't reproduce. |
Hmm, I just so happened to have this issue up while debugging my project this morning, and at least for my project I'm still encountering this even after refreshing my lockfile. I am using PrimeVue with Nuxt, and have a large amount of my pages client side only for auth related reasons. When accessing a page that uses a new PrimeVue component, it triggers dependency optimization and reloads the page. Not sure if the problem is actually more related to Prime, but I am also using As you can imagine, especially given that each route only loads a subset of components, this leads to about every page requiring a full reload in development. I know that |
I am using clean Nuxt 3.8.1 (SPA) and have just (5 Minutes ago) regenerated the package-lock.json with ...
components: {
global: true,
dirs: ['~/components'],
},
... I still have the problem every time I call a new .vue file. |
Would you be able to provide a reproduction? 🙏 More infoWhy do I need to provide a reproduction?Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. What will happen?If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect. If How can I create a reproduction?We have a couple of templates for starting with a minimal reproduction: 👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz A public GitHub repository is also perfect. 👌 Please ensure that the reproduction is as minimal as possible. See more details in our guide. You might also find these other articles interesting and/or helpful: |
If you're still experiencing this, would you provide a reproduction? 🙏 |
@danielroe even with original reproduction as part of this issue, I have removed lock file and modules, fresh pnpm install but optimizations are still happening on my side. |
@danielroe Here's a reproduction I created just now. It includes pages using different features such as suspense and client side only. One extra thing worth noting is I needed to disable prefetching on You'll see that clicking between each of the pages causes a dependency optimization and triggers a full page reload. |
Is there any progress on this problem? |
I don't believe this is a Nuxt issue but more likely a vite one that will be resolved when updating to Vite 5. However, I can't investigate further as the reproduction doesn't reproduce the issue for me. It only prints it once into the console, and subsequent HMR and restarts of the dev server do not trigger re-optimising dependencies. |
Copy that! I will be curious to see if Vite 5 alleviate this as well. It could also be my use case of developing inside a container making this harder to replicate, as this may be what leads to it not being a one-time optimization but an optimization every time my container is restarted. If the reproduction I provided does optimize dependencies and reload the page on every initial route with a new dependency, for me this is what happens after every restart. Either way, I appreciate the investigation and your hard work on Nuxt! |
I don't understand this problem fully, but for what it's worth I'm also experiencing it and I do not use a container. I work locally and am getting the optimize message/app reload every time I go to a page that includes a new dependency, e.g. from Lodash. |
This comment was marked as duplicate.
This comment was marked as duplicate.
Hi, I had the same issue. Not sure which change in nuxt@3.8.1 caused it because it didn't happen in v3.8.0, but I managed to prevent it by adding following to the nuxt.conifg: |
Specifying the name of node_modules packages in the configuration vite optimizeDeps.include corrects the problem. |
The error also occurs in the nuxt-nightly version. |
I will look into it. You can try to debug this as well by passing The thing I found is that every time Nuxt starts, the previous optimization cache is got removed: With the insight from @patak-dev, I guess it's because the hash Vite calculated are not consistent across multiple run:
I will dig and see what it causing that. |
So, as you see on the linked PRs above, this is caused by quite a few moving parts. Basically it's because different Nuxt modules might contribute to the Vite config at a different time (racing conditions), and causing the Vite config to be unstable across runs and the hash being different: https://github.com/vitejs/vite/blob/c902545476a4e7ba044c35b568e73683758178a3/packages/vite/src/node/optimizer/index.ts#L1210-L1226 So basically, any module could cause that. The main one should be Nuxt DevTools (nuxt/devtools#542) where the fix is already released as v1.0.6. Then we have On the Vite side, fixes and proposals are on the way to make the experience better:
There is currently no userland workaround at this moment, please be patient for all those packages to be upgraded. Will keep this post updated. |
Ooh, nice find! It did feel like there was a bigger issue looming. I'll need to keep an eye out for this on my modules, the upstream PRs should help with that though. |
Awesome work! Not sure if this is the best place to track it anymore, but combing through the modules used in my project I found a place in the https://github.com/vueuse/vueuse/blob/main/packages/nuxt/index.ts#L75-L79 |
Working after upgrade to |
Can confirm it works well with |
This issue was solved on my end too. I just did a weekly package update and it's happening again. Should I file something in the Vite repo? Has anyone else had the issue happen again? I'm not exactly sure which package is causing the issue, but here are some of the packages that were updated that I think could be related.
|
I also updated to 3.9.3 and issue is still there but it happens less often. It seems to happen every time package-lock is updated (even if updated dependency is not the one that needs to be optimised). |
That's vite's intended behaviour - it will reoptimise deps when your lockfile changes. |
In my case, my lockfile is not changing. I'm experiencing app reloads when running |
@danielroe I understand but I think it would be a bit nicer developer experience if they are all optimised before page is served. Currently I start the server then it reloads 3 times for each dependency and then again on route change where another package is used. |
Hey @danielroe, Edit: You can reproduce it with the example project at the top of the issue |
cc: @antfu |
This issue gets a bit long and quite a lot of context involved - could anyone create a new issue linking back to this one, and with a reproduction of the latest nuxt? Otherwise I am not so sure what to "fix" - thank you! |
I'll close here in favor of #26783 then to keep focus on the issue 👍🏻 |
Environment
Reproduction
https://github.com/frasza/nuxt-optimize-deps
Describe the bug
Since Nuxt 3.8.1 I (and few others on Discord) have noticed on development app boot that Nuxt/Vite does some dependencies optimization and it happens quite often (sometimes even on every page refresh, sometimes I noticed only once per dev server startup). Problem is that is also does full page refresh.
Provided small reproduction using
tiptap
editor. On my own project I have even more of these packages that produce the issue.It really does impact DX since its doing full page refresh when it happens. If I revert to Nuxt 3.8.0, issue is gone.
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: