いつも通り意味不明なNext.jsのエラー
エラーメッセージたち
"next dev"の場合
⨯ [TypeError: Cannot read properties of undefined (reading 'deploymentId')]
⨯ [TypeError: Cannot read properties of undefined (reading 'deploymentId')]
GET / 500 in 5411ms
✓ Compiled /favicon.ico in 121ms
⨯ [TypeError: Cannot read properties of undefined (reading 'buildId')]
⨯ [TypeError: Cannot read properties of undefined (reading 'buildId')]
deploymentId
もbuildId
もプロジェクト内では使っていません
"next build"の場合
✓ Linting and checking validity of types
✓ Collecting page data
// ここまではOK
Error: <Html> should not be imported outside of pages/_document.
Read more: https://nextjs.org/docs/messages/no-document-import-in-page
at b (.next/server/pages/_document.js:6:1351)
Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
Error: <Html> should not be imported outside of pages/_document.
Read more: https://nextjs.org/docs/messages/no-document-import-in-page
(大量のトレースバック)
Export encountered an error on /_error: /404, exiting the build.
⨯ Next.js build worker exited with code: 1 and signal: null
エラー系のページは特に作成していないのですべてデフォルトです。デフォルト実装の404ページがエラーしています。
解決策
Nextのキャッシュとインストールしたパッケージをすべて消去すれば治ります。
rm -rf ./.next && rm -rf ./node_modules
Nextを消すほうは一度やった気がするので、node_modulesのどこかがおかしくなっていたと思われます。