nextjs - 💡(How to fix) Fix Turbopack: Dynamic Imports Error when path is not statically analyzable [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#85238Fetched 2026-04-08 02:16:57
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Timeline (top)
commented ×2labeled ×2issue_type_added ×1renamed ×1

Code Example

Module not found: Can't resolve '.' <dynamic> '/page'
  4 |   const path = atob('L1tsb2NhbGVd') // = '/[locale]'
  5 |
> 6 |   await import(`.${path}/page`)
    |         ^^^^^^^^^^^^^^^^^^^^^^^
  7 |
  8 |   return []
  9 | }

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:26 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6041
  Available memory (MB): 49152
  Available CPU cores: 14
Binaries:
  Node: 22.17.1
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.17.1
Relevant Packages:
  next: 16.0.0 // Latest available version is detected (16.0.0).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: N/A
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/madebyfabian/nextjs-turbopack-dynamic-imports-reprod

To Reproduce

  1. Start the application in dev
  2. Visit http://localhost:3000/sitemap.xml

Current vs. Expected behavior

Currently, this errors:

Module not found: Can't resolve '.' <dynamic> '/page'
  4 |   const path = atob('L1tsb2NhbGVd') // = '/[locale]'
  5 |
> 6 |   await import(`.${path}/page`)
    |         ^^^^^^^^^^^^^^^^^^^^^^^
  7 |
  8 |   return []
  9 | }

But this works fine with webpack, so it would be expected to work in turbopack the same way. (the atob is just there to simulate a string that is not statically analyzable, since in my real application, this string comes from a list of folder names retrieved by fs.readdirSync.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:26 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6041
  Available memory (MB): 49152
  Available CPU cores: 14
Binaries:
  Node: 22.17.1
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.17.1
Relevant Packages:
  next: 16.0.0 // Latest available version is detected (16.0.0).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: N/A
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

This is used in a current Next.js 15 (Webpack) application during build to generate the sitemap. It's used to:

  • Retrieve a list of all app routes inside the /app directory with fs.readdirSync
  • Import the generateStaticParams method from every routes page.tsx file to then generate all unique params for this route.

Maybe there is a better way to do this, but this is what I found was working to generate a true dynamic sitemap without duplicating everything in every route's generateStaticParams

extent analysis

TL;DR

The issue can be fixed by adjusting the dynamic import statement to work with Turbopack, which may require using a different approach to handle dynamic imports.

Guidance

  • Review the Turbopack documentation to understand how it handles dynamic imports, as it may differ from Webpack.
  • Consider using next/dynamic with a custom loader function to handle dynamic imports in Turbopack.
  • Verify that the atob function is not the cause of the issue by testing with a static string.
  • Investigate alternative approaches to generating the sitemap, such as using a separate build step or a library specifically designed for dynamic sitemaps.

Example

// Example of using next/dynamic with a custom loader function
import dynamic from 'next/dynamic';

const Page = dynamic(() => import(`./page`), {
  loader: () => import(`./loader`),
});

Notes

The issue is specific to Turbopack and may require a different solution than what works with Webpack. The use of atob to simulate a dynamic string may be a red herring, and the issue may be related to how Turbopack handles dynamic imports.

Recommendation

Apply a workaround by using a different approach to handle dynamic imports, such as using next/dynamic with a custom loader function. This is because the current implementation is not compatible with Turbopack, and adjusting the import statement or using a different library may be necessary to resolve the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING