探してもコレといったものが見つからなかったので、未来の自分への備忘録と、同じ問題に悩んでる人がもしいたら参考になれば幸いですという思いを込めて。
環境
以下を使用したアプリケーション構成。
Firebase Hosting/Functions
Next.js
事象
ある日、deployしたWebアプリケーションがエラーを吐いて動かなくなった。
エラーは以下。(Cloud Functionsのログに出力されていた)
Error: Cannot find module '/workspace/.next/server/font-manifest.json'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.mod._resolveFilename (/workspace/node_modules/next/dist/build/webpack/require-hook.js:4:1784)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at requireFontManifest (/workspace/node_modules/next/dist/next-server/server/require.js:1:1723)
at new Server (/workspace/node_modules/next/dist/next-server/server/next-server.js:3:729)
at NextServer.createServer (/workspace/node_modules/next/dist/server/next.js:1:2935)
at process._tickCallback (internal/process/next_tick.js:68:7)
対応
実際のところ原因はわかってないのだが、Cloud FunctionsのランタイムのNode.jsのバージョンを10→12に変えてdeployしたら直った。
firebase.jsonのfunctions.runtimeのところを修正すればよい。
...
"functions": {
"source": ".",
"predeploy": [
"npm --prefix \"$PROJECT_DIR\" install",
"npm --prefix \"$PROJECT_DIR\" run build"
],
"runtime": "nodejs12" ←ここを"nodej10"から"nodejs12"に変更した
}
...
firebase initで、functions選んでた場合、Cloud Funtionsのランタイムのデフォルト値がNode.js 10になるようなので(少なくともfirebase initしてから変えたことはなかった)、FirebaseでNext.jsのアプリケーションを組む場合は注意したほうが良いかと。
関連
似たようなエラーが発生した事例として、2019年頃のissueで取り扱われているものがある。
https://github.com/vercel/next.js/issues/6287
※このissueの事例は「pages-manifest.jsonが見つからない」のに対し、私の事例は「font-manifest.jsonが見つからない」なので、同じエラーというわけではない。単にググってひっかかった似たエラーの事例というだけである
ここでのやり取りを見る限り、以下のようなことをやったら(+.nextディレクトリ消してnext buildを再度実行)解決した、と書かれている。
- next.config.jsのserverless:trueを削除
- getInitialPropsにasyncを付けていなかったので付けた
ただ私の例だとnext.config.jsにはもともとserverless:trueの設定は書いてなかったし、getInitialpropsも使ってなかった(getStatisPropsとかgetServerSidePropsは使ってたけどそっちはちゃんとasync付けてた)ので、やはり厳密に同じ事例ではないらしい。
まあ2019年の事例だしね。。。
↧