-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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.11.2 #26783
Comments
I did a bit of research. Nuxt 3.10.3 version uses Vite 5.1.4 and since vite 5.1.5 the problem persists again. After reading the changelog, I noticed that changes were made to the optimized deps again. |
This is indeed very annoying. As a workaround, I added all libraries that appeared in the messages to this include array in the nuxt config:
🤷♂️ |
@antfu How are things looking, any news? |
Why is the issue only |
cc: @antfu - any ideas? |
It is difficult to fix the problem since the warning appears only in existing projects, updating the project does not help. If you start a new project, there will be no warning. I get a warning when I use prime vue, vee-validate, yup. |
Has anyone tried using I'm not familiar with Nuxt's architecture, but I suppose client routes (and thus its dependencies) are lazily loaded before each navigation and that would require Vite to run deps optimization, which then involves browser full reload. I think this is a common issue and I remember these two recent issues in other frameworks:
The reproduction given in this issue is probably the simplest case, but at least for this one, Vite can correctly crawl Show logs of vite:deps$ DEBUG=vite:deps pnpm dev
...
vite:deps Scan completed in 1449.13ms:
vite:deps @tiptap/starter-kit -> (my-dir)/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@tiptap/starter-kit/dist/index.js
vite:deps @tiptap/vue-3 -> (my-dir)/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@tiptap/vue-3/dist/index.js +1s
vite:deps creating package.json in (my-dir)/node_modules/.cache/vite/client/deps_temp_db14d463 +1s
[nitro] rollup:before: 414.45ms 4:52:29 PM
[nitro] types:extend: 0.023ms 4:52:29 PM
ℹ Vite server warmed up in 1902ms 4:52:29 PM
vite:deps ✨ static imports crawl ended +2s
vite:deps Dependencies bundled in 1058.13ms +1s
vite:deps removing cache dir (my-dir)/node_modules/.cache/vite/client/deps_temp_db14d463 +3ms
vite:deps ✨ new dependencies were found while crawling that weren't detected by the scanner +153ms
vite:deps ✨ re-running optimizer +0ms
vite:deps new dependencies found: vue, vue-router, @tiptap/starter-kit, @tiptap/vue-3, ofetch, ufo, defu +3ms
vite:deps creating package.json in (my-dir)/node_modules/.cache/vite/client/deps_temp_011fd118 +6ms
vite:deps Dependencies bundled in 394.41ms +397ms
vite:deps creating _metadata.json in (my-dir)/node_modules/.cache/vite/client/deps_temp_011fd118 +80ms
vite:deps renaming (my-dir)/node_modules/.cache/vite/client/deps_temp_011fd118 to (my-dir)/node_modules/.cache/vite/client/deps +2ms
vite:deps ✨ dependencies optimized +480ms However, in practice, this might not be enough since Vite deps optimization scan (thus esbuild) doesn't actually transpile .vue file during this phase (it looks like it's simply extracting |
For everyone who encounted the issue, please try this module and let us know how it would improve for you. Thanks! |
I downloaded this package, there seem to be fewer reboots, but they still happen when import is needed. The restart starts only when there is a new non-imported element on the page. |
@Frallen could you share the repo so I could have a look? Thanks |
I have a private project 😢. I will try to make a repository and repeat the behavior |
@Frallen please give a try with nuxt-better-optimize-deps v0.1.0 - hope that would make it better for you |
Thanks, it's much better! 🎉 So now the ecosystem libraries are excluded from optimization. optimizeDeps: {
include:[
"libphonenumber-js",
"markdown-it-mathjax3",
"markdown-it",
"yup",
"highlight.js",
"vee-validate",
]
} |
@antfu and should module authors also exclude themselves if library supports ESM? |
I would say yes: https://github.com/nuxt/nuxt/pull/27372/files#diff-5a9de16d770e29c763f4acdc8596643eb6486d6efc14ebe37165ebfc8cb4a419R70-R73 especially there is a chance for your library to be depended by other libraries. |
This should be resolved mostly through #27372, right? |
When you say mostly do you mean that the problem occurs under some circumstances? |
It resolves probably the vast majority of issues with optimizeDeps. I can't reproduce the issue in the original reproduction provided above, so I'm going to mark it as resolved in the nightly release, or in the next release. It is normal for vite occasionally to print |
Same problem using primevue, vee-validate, yup. |
So the solution is to list every third party dependancy in I wouldn't mind waiting for an extra 20 seconds on dev server startup for vite to scan my entire project and optimise ahead of time. I want to test the UX and the page reloading everytime it finds a new unimported dependancy really hinders that. |
Are you using pnpm? |
npm |
Environment
Reproduction
https://github.com/Letsion/nuxt-optimize-deps
Describe the bug
Since Nuxt 3.11.0 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.
See it the old issue: #24196
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: