Closed8

firebase functions emulator の "Functions codebase could not be analyzed successfully" エラー対応

nbstshnbstsh

下記エラーが出て動かなくなった

⬢  functions: Failed to load function definition from source: FirebaseError: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error

解決までの道のりメモしていく

nbstshnbstsh

--debug flag つけて、詳細な log を確認

しかし、目ぼしいエラーメッセージなし

nbstshnbstsh

エラーの原因の箇所を特定するために、コードをコメントアウトしていく

nbstshnbstsh

nanoid 使ってるとこを消すとうまくいくぞ

なぜだ...?

nbstshnbstsh

esm だ!

Nano ID 5 works only with ESM projects, in tests or Node.js scripts. For CommonJS you need Nano ID 3.x (we still support it):

nanoid の v5 は ESM project のみ対応。CommonJS project で利用したい場合は v3 系を利用とのこと。

https://github.com/ai/nanoid#install

nbstshnbstsh

解決

ESM only の nanoid を除外することで対応。

Firebase functions のコードは、firebase CLI で init すると CommonJS で用意される (2023/10/14 現在) ので、ESM only の library 入れる場合は要注意だな。

このスクラップは2023/10/14にクローズされました