0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Next.js ビルド時に「 Could not find files for /_error in .next/build-manifest.json」エラーが発生する

Posted at

不具合の内容

  • 発生タイミング: next build 実行時
  • 環境:
    • フレームワーク: Next.js 15.3.5
    • 言語: TypeScript
    • OS: Linux
    • その他: App Router構成、React Server Components あり

実際のエラーメッセージ

Could not find files for /_error in .next/build-manifest.json
TypeError: Cannot read properties of undefined (reading 'call')
    at Object.t [as require] (.next/server/webpack-runtime.js:1:511)
    at JSON.parse (<anonymous>)
Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /_not-found/page: /_not-found, exiting the build.
 ⨯ Next.js build worker exited with code: 1 and signal: null

原因の調査

  1. エラーメッセージから /_not-found ページのプリレンダリング時に問題が発生していることを確認
  2. not-found.tsx"use client" ディレクティブが静的エクスポートで問題を起こしている可能性を疑う
  3. Next.jsキャッシュ(.nextフォルダ)のクリアを実施するも問題継続
  4. デバッグモードの無効化を試すも改善せず
  5. 実際の原因: 以前に起動したNext.js開発サーバーのプロセスが残存しており、ビルド時に競合状態を引き起こしていた

🛠 解決方法

以下の対応で問題を解消:

1. Next.jsサーバープロセスの確認と停止

# Next.jsサーバーのプロセスを確認
ps aux | grep next

# または Node.jsプロセス全体を確認
ps aux | grep node

# プロセスを強制終了(PIDを確認してから実行)
kill -9 [PID]

結果

  • サーバープロセスの停止により、ビルドエラーが完全に解消
  • next build が正常終了するように
  • 静的プリレンダリングが正常に動作

⚠ 試したが意味のなかったこと

試したこと 結果 コメント
.next フォルダの削除 キャッシュクリアでは解決せず
not-found.tsx"use client" 削除 一時的改善も根本解決にならず
ビルド時のデバッグモードの有効化 -dでも同じエラーしか出てこない
/_error ファイルの作成 App Routerでは不要

補足・学び

  • Next.js開発サーバーのプロセス管理は重要で、残存プロセスがビルド時に予期しない競合を引き起こす
  • ps aux | grep nextps aux | grep node でプロセス確認する習慣が大切
  • ビルドエラーが発生した際は、環境・プロセスの状態確認も重要な調査項目

関連リンク

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?