third party library, lazy loading, dev server complains, static build is fine #9601
Replies: 2 comments 8 replies
-
Some observations from shotgun debugging of this:
I'd really like to understand where does the error come from in Really puzzled by this :) |
Beta Was this translation helpful? Give feedback.
-
This likely happens because the One option, as you already discovered, would be using a client-side plugin. Another option would be adding a wrapper (as you did) which lazy-loads the I actually did sth. similar in a project using
<template>
<Gallery :images="images" :index="index" @close="$emit('close')" />
</template>
<script>
export default {
components: {
Gallery: () => import('vue-gallery/src/component/gallery.vue')
},
props: {
images: {
type: Array,
required: true
},
index: {
type: Number,
required: true
}
}
}
</script> On the page, say <template>
<ClientOnly>
<GalleryWrapper :images="images" :index="index" @close="index = null" />
</ClientOnly>
</template> Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
tl;dr: I get a dynamic component resolution problem in dev server only despite lazy loading and I can't figure out why.
I'm making a nuxt version of my website. I want to continue using lightgallery for the images. It has an official vue wrapper, but only for vue3. Regardless of the vue version, that library accesses
window
during import, and as such causes problems with ssr enabled. The author admits as much, and recommends dynamic loading (eg. here).Now, I wrote my own simple vue 2 component for lightgallery. I've wrapped the instantiation of that component in
<client-only>
and prefixed the name of the component withlazy
as seen here. To my surprise, this still resulted in following error produced on both the terminal and browser's console when I visited a page using that component on the dev server:The gallery works more or less fine from what I can tell, despite this error. I had some hiccups when I initially wrote this question, but I think I can chalk it up to browser misbehaving on my end. What's most perplexing to me, the site works fine once generated for static serving - that is,
yarn generate
. This fact really makes me think this tickles some weird bug in nuxt that is specific to the dev server.My project's code at the version displaying this behaviour is here and here is a matching netlify build. I don't have any experience with modern webdev and webpack - so tracing this down takes a lot of time and effort. I'd be grateful for some sort of diagnosis here :D
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions