Next.js + Firebase Functionsが同居するリポジトリでnext buildを実行するとエラーが発生
Next.js + Firebase Functionsが同居するリポジトリで next build を実行したところ、下記のエラーが発生した。
Type error: Cannot find module 'xxx' or its corresponding type declarations.今回、Next.jsもFirebase FunctionsもTypescriptで開発を行っており、Functionsのコードは ./functions 以下で管理するようにしていた。
tree -L 1
.
├── functions
│ ├── package.json
│ ├── src
│ └── tsconfig.json
├── tsconfig.json
├── package.json
└── pagespackage.json がNext.jsとFirebase Functionsで別管理になっているにも関わらず、 next build 時にfunctions以下のコードもビルドしようとしたため Cannot find module エラーが発生していた。
そこでNext.js用の tsconfig.json に exclude 設定を追加して、functions 以下を除外するようにした。
{
"compilerOptions": {
// ...
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", "functions"]
}これでエラーなく next build が実行できるようになった。