global-not-found breaks with any import (infinite dev loop, high CPU) in Next 16.2.x
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/intoRandom/next-global-not-found-import-bug
To Reproduce
- Create a new Next.js app:
pnpm create next-app@latest
- Create route groups:
mkdir -p app/'(group1)' app/'(group2)'/path && \
cp app/page.tsx app/'(group1)'/page.tsx && \
cp app/layout.tsx app/'(group1)'/layout.tsx && \
cp app/layout.tsx app/'(group2)'/layout.tsx && \
cp app/page.tsx app/'(group2)'/path/page.tsx
- Remove root layout and page:
rm app/page.tsx app/layout.tsx
- Enable experimental flag in next.config.ts:
export default {
experimental: {
globalNotFound: true,
},
}
- Create app/global-not-found.tsx with an import:
import './globals.css';
export default function GlobalNotFound() {
return (
<html lang="en">
<body>
<h1>404 - Page Not Found</h1>
<p>This page does not exist.</p>
</body>
</html>
);
}
- Run:
pnpm run dev
Current vs. Expected behavior
Expected:
- global-not-found renders correctly
- dev server remains stable
Actual:
- Page fails to render correctly (blank or inconsistent)
- Dev server enters an infinite loop
- Multiple Node processes spawn
- High CPU usage
Key finding:
The issue is triggered by any import inside global-not-found.tsx.
Working version (no imports, same HTML structure):
export default function GlobalNotFound() {
return (
<html lang="en">
<body>
<h1>404 - Page Not Found</h1>
<p>This page does not exist.</p>
</body>
</html>
);
}
```tsx
### Provide environment information
```bash
Operating System:
Platform: linux
Arch: x64
Version: #20~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 01:28:37 UTC 2
Available memory (MB): 11851
Available CPU cores: 4
Binaries:
Node: 25.1.0
npm: 11.6.2
Yarn: N/A
pnpm: 10.32.1
Relevant Packages:
next: 16.2.2 // Latest available version is detected (16.2.2).
eslint-config-next: N/A
react: 19.2.4
react-dom: 19.2.4
typescript: 5.9.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Not Found
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
-
The issue occurs even with minimal imports such as:
import './globals.css'; -
The problem is not related to JSX structure. The same component works correctly when no imports are present.
-
Regression:
- Works in next@16.1.6
- Broken in next@16.2.1 and 16.2.2
-
Likely related to how global-not-found is handled as a special entry in the module graph when no root layout is present.
-
Reproducible locally.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the linked reproduction with next@16.1.6 and 16.2.2, focusing on app/global-not-found.tsx, its CSS import, and next.config.ts with experimental.globalNotFound enabled. Trace how global-not-found is handled as a special entry when no root layout exists, then verify that the page renders and next dev remains stable without spawning processes or looping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, typescript
- Domain
- devtools, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100