Fixing Swiper Component displayName Loss with Next.js Dynamic Import
Key point
Rendering errors caused by Next.js Dynamic Import stripping the Swiper component's displayName can be resolved by manually setting it or using the transpilePackages option.
Details
When loading the Swiper library via Dynamic Import in Next.js, the original component's displayName field is lost during the Loadable Component wrapping process. Since Swiper internally uses displayName to identify child elements (SwiperSlide), if this field becomes undefined, slides fail to arrange correctly and appear as a simple scrollable list.
There are two solutions. First, manually assign the displayName to the component imported via Dynamic Import, such as SwiperSlide.displayName = "SwiperSlide". Second, configure the transpilePackages option provided in Next.js 13.1 or later in next.config.js to directly transpile Swiper and related modules (ssr-window, dom7). The latter fundamentally resolves issues with modules that do not support CommonJS, resulting in the cleanest code solution.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.