nextjs - 💡(How to fix) Fix Turbopack HMR stops working after first edit for dynamically imported JSON files (16.2 regression) [4 comments, 3 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#91768Fetched 2026-04-08 01:12:06
View on GitHub
Comments
4
Participants
3
Timeline
11
Reactions
1
Assignees
Timeline (top)
commented ×4labeled ×2referenced ×2assigned ×1

Root Cause

The root cause appears to be the new Server Fast Refresh feature in 16.2 which uses Turbopack's fine-grained module graph invalidation instead of clearing the full require.cache. Dynamic import() with template literals (e.g., import(`../../messages/${locale}.json`)) cannot be statically analyzed by Turbopack, so after the first resolution, the JSON file is not tracked in the module graph for subsequent change detection.

Fix Action

Fix / Workaround

Workaround: Using next dev --webpack works correctly for all edits.

Code Example

// src/i18n/request.ts
const messages = (await import(`../../messages/${locale}.json`)).default;
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/guoxinghuang/nextjs-turbopack-hmr-repro

To Reproduce

  1. pnpm install
  2. pnpm dev (uses Turbopack, the default in Next.js 16)
  3. Open http://localhost:3000
  4. Edit messages/en.json — change the "hello" value and save
  5. The page updates correctly (first edit works)
  6. Edit messages/en.json again — change the "hello" value and save
  7. The page does NOT update (subsequent edits are ignored)

Current vs. Expected Behavior

Current: Only the first edit to a JSON file loaded via dynamic import() with a template literal triggers HMR. All subsequent edits are silently ignored until the dev server is restarted.

Expected: Every edit should trigger HMR and update the page, as it did in Next.js 16.1.

Provide environment information

  • Next.js: 16.2.1
  • next-intl: 4.8.3
  • React: 19.x
  • Node: 22.x
  • OS: macOS (Darwin 25.3.0)

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

Turbopack, HMR

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

next dev (local)

Additional context

This is a regression introduced in Next.js 16.2. It worked correctly in 16.1.

The root cause appears to be the new Server Fast Refresh feature in 16.2 which uses Turbopack's fine-grained module graph invalidation instead of clearing the full require.cache. Dynamic import() with template literals (e.g., import(`../../messages/${locale}.json`)) cannot be statically analyzed by Turbopack, so after the first resolution, the JSON file is not tracked in the module graph for subsequent change detection.

Workaround: Using next dev --webpack works correctly for all edits.

This pattern is commonly used with next-intl for loading i18n message files per locale:

// src/i18n/request.ts
const messages = (await import(`../../messages/${locale}.json`)).default;

extent analysis

Fix Plan

To fix the issue with HMR not working for subsequent edits to JSON files loaded via dynamic import() with template literals in Next.js 16.2, we need to use a workaround until the issue is resolved in Turbopack.

Here are the steps:

  • Use the --webpack flag with next dev to bypass Turbopack and use Webpack instead, which does not have this issue.
  • Alternatively, you can modify your next.config.js to use Webpack by default for development.

Example next.config.js modification:

module.exports = {
  //... other configurations ...
  turbopack: process.env.NODE_ENV === 'production',
}

Then, run your development server with:

NODE_ENV=development next dev

Or, you can use the --webpack flag directly:

next dev --webpack

This will ensure that Webpack is used for development, allowing HMR to work correctly for all edits.

Verification

To verify that the fix worked, follow these steps:

  • Run your development server with the modified configuration or the --webpack flag.
  • Edit a JSON file loaded via dynamic import() with a template literal.
  • Save the changes and verify that the page updates correctly.
  • Repeat the edit and save process to ensure that HMR works for subsequent edits.

Extra Tips

  • Keep an eye on the Next.js and Turbopack issue trackers for a permanent fix to this regression.
  • If you are using next-intl for i18n, consider exploring alternative solutions that do not rely on dynamic import() with template literals.

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