Next.jsApp RouterError Fix2026 Updated
Next.js Dynamic Import Not Working App Router— Fixed [2026]
Also covers: ssr:false not working · lazy loading · next/dynamic Client Component
January 20265 min readNext.js 13–15 · App Router
⚡ Quick Fix — Add 'use client'
components/ChartWrapper.jsx
'use client' // ← required for next/dynamic with ssr: false
import dynamic from 'next/dynamic'
const Chart = dynamic(() => import('./Chart'), {
ssr: false,
loading: () => <p>Loading chart...</p>,
})
export default function ChartWrapper({ data }) {
return <Chart data={data} />
}Why Dynamic Import Behaves Differently in App Router
In Next.js App Router, all components are Server Components by default. next/dynamic is a Client Component feature — it works with React's lazy loading system which runs in the browser. Using ssr: false in a Server Component is either ignored or causes errors.
| Scenario | Correct approach |
|---|---|
| Client Component — lazy load with ssr:false | next/dynamic with 'use client' |
| Server Component — code split async | Native await import() in async component |
| Avoid hydration mismatch (window API) | dynamic() with ssr: false in Client Component |
| Heavy chart / map library | dynamic() wrapping Client Component |
11 min
Dynamic Import Must Be in a Client Component
Most common fix — missing 'use client'components/MapWrapper.jsx
'use client' // ← REQUIRED
import dynamic from 'next/dynamic'
// ✅ Dynamic import in Client Component
const LeafletMap = dynamic(() => import('./LeafletMap'), {
ssr: false,
loading: () => <div className="h-64 bg-gray-100 animate-pulse rounded" />,
})
export default function MapWrapper({ center, zoom }) {
return <LeafletMap center={center} zoom={zoom} />
}
// Then use in a Server Component page:
// import MapWrapper from '@/components/MapWrapper'
// <MapWrapper center={[51.5, -0.09]} zoom={13} />22 min
ssr: false — Client-Only Libraries
window / document / browser-only APIsUse ssr: false for components that use browser APIs unavailable on the server, or third-party widgets that break during SSR.
components/ClientWidgets.jsx
'use client'
import dynamic from 'next/dynamic'
// Leaflet (map) — requires window
const Map = dynamic(() => import('./Map'), { ssr: false })
// Monaco Editor — requires browser DOM
const Editor = dynamic(() => import('@monaco-editor/react'), { ssr: false })
// Lottie animation — browser canvas API
const Lottie = dynamic(() => import('lottie-react'), { ssr: false })
// Chart.js — requires canvas
const LineChart = dynamic(
() => import('react-chartjs-2').then(mod => mod.Line),
{ ssr: false }
)32 min
Loading and Error States
Show skeleton while chunk loadscomponents/HeavyComponent.jsx
'use client'
import dynamic from 'next/dynamic'
const HeavyEditor = dynamic(() => import('./HeavyEditor'), {
ssr: false,
loading: () => (
<div className="flex items-center justify-center h-64 bg-gray-50 rounded-xl">
<div className="flex items-center gap-2 text-gray-400">
<div className="w-4 h-4 border-2 border-indigo-600 border-t-transparent rounded-full animate-spin" />
<span>Loading editor...</span>
</div>
</div>
),
})
export default function EditorPage() {
return (
<div>
<h1>Document Editor</h1>
<HeavyEditor />
</div>
)
}42 min
Dynamically Import Third-Party Libraries
Reduce initial bundle sizecomponents/ExportButton.jsx
'use client'
export default function ExportButton({ data }) {
async function handleExport() {
// Import heavy library only when button is clicked
const { default: XLSX } = await import('xlsx')
const ws = XLSX.utils.json_to_sheet(data)
const wb = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')
XLSX.writeFile(wb, 'export.xlsx')
}
return <button onClick={handleExport}>Export to Excel</button>
}
// This pattern works for any heavy library:
// PDF generation: pdfmake, jspdf
// Image processing: sharp (in API routes), canvas
// QR codes: qrcode, react-qr-code51 min
Named Exports With dynamic()
Import a specific named exportcomponents/SpecificChart.jsx
'use client'
import dynamic from 'next/dynamic'
// ✅ Named export — wrap in arrow function returning the named export
const BarChart = dynamic(
() => import('recharts').then(mod => ({ default: mod.BarChart })),
{ ssr: false }
)
// ✅ Multiple named exports from same package
const LineChart = dynamic(
() => import('recharts').then(mod => ({ default: mod.LineChart })),
{ ssr: false }
)62 min
Native import() in Server Components
Code splitting without next/dynamicServer Components support native import() with async/await — no next/dynamic needed.
app/report/page.jsx
// Server Component — native async import works perfectly
export default async function ReportPage() {
// Conditionally load heavy module
if (process.env.NODE_ENV === 'development') {
const { generateDebugReport } = await import('@/lib/debug-report')
await generateDebugReport()
}
// Load based on feature flag
const renderer = await import(
process.env.USE_NEW_RENDERER === 'true'
? '@/lib/new-renderer'
: '@/lib/old-renderer'
)
return <div>{await renderer.render()}</div>
}Prevention
- Always add 'use client' to files using next/dynamic with ssr: false
- Create a Client Component wrapper for any dynamically imported library
- Use the loading prop to show a skeleton — improves perceived performance
- For Server Components, use native await import() instead of next/dynamic
- Use inline import() in event handlers for click-triggered heavy libraries
Frequently Asked Questions
Why is next/dynamic not working in App Router?+−
next/dynamic with ssr: false must be used in a Client Component (has 'use client'). In App Router, Server Components are default — you must opt in to client rendering. If you call next/dynamic in a Server Component, the ssr: false option is ignored and may cause errors.
How do I use dynamic import with ssr: false in App Router?+−
Add 'use client' to the file where you call dynamic(): 'use client'; import dynamic from 'next/dynamic'; const Chart = dynamic(() => import('./Chart'), { ssr: false }). The ssr: false option prevents SSR for that component only.
When should I use ssr: false in Next.js?+−
Use ssr: false for components that use browser-only APIs (window, localStorage, document), third-party widgets that do not support SSR, heavy libraries only needed on the client, or components that cause hydration errors due to browser-only code.
Can I use dynamic() in a Server Component?+−
dynamic() from 'next/dynamic' is designed for Client Components. In Server Components, use native async import(): const { default: Chart } = await import('./Chart'). This is true code splitting and works with Server Component async/await.
Dynamic import loading state not showing — why?+−
The loading component only shows during the lazy load phase (first time the component is needed). If the chunk is already cached by the browser, loading shows only for milliseconds. In development, chunks load fresh every time so loading is more visible.
How do I dynamically import a named export?+−
Pass the specific export in the factory function: const { SpecificComponent } = await import('./components'); const DynamicComp = dynamic(() => import('./components').then(mod => mod.SpecificComponent));
Need Expert Help?
We Build Production-Grade Next.js Apps
Softplix builds full-stack Next.js applications. Need help with performance, code splitting, or App Router patterns? We can help.
Talk to an Engineer