firebase-functions-test
を使ってテストを実行しようとした結果、次のようなエラーが発生しました。
Cannot find module 'firebase-functions/lib/encoder' from 'node_modules/firebase-functions-test/lib/providers/firestore.js'
色々調べてみると、次のような投稿が見つかりました。
After stumbling on Farid's suggestion for this problem, I realized that, for some reason, npm i firebase-functions-test does not install the latest version of the module.
Try npm i firebase-functions-test@latest.
しかし、npm install --save-dev firebase-functions-test@latest
を実行しても次のようなエラーが発生しました。
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: functions@undefined
npm ERR! Found: firebase-functions@3.24.1
npm ERR! node_modules/firebase-functions
npm ERR! firebase-functions@"^3.18.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer firebase-functions@"^4.0.0" from firebase-functions-test@3.0.0
npm ERR! node_modules/firebase-functions-test
npm ERR! dev firebase-functions-test@"3.0.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
...
最新バージョンのfirebase-functions-test
をインストールするためには、firebase-functions
のバージョン自体も最新版にする必要があるようです。
それでは、firebase-functions
とfirebase-functions-test
のバージョンを最新にします。
もし現在、僕と同じように3.x.x
系のfirebase-functions
を使っている場合は新しい環境を要してから最新版にアップデートして正しく動作するかの検証を行なってからコミットすることをお勧めします。
- ローカルにリポジトリを新しいディレクトリ名を使ってクローンする
-
functions
ディレクトリ内でnpm install
を実行す -
npm instal firebase-functions@latest
を実行する -
npm install --save-dev firebase-functions-test@latest
を実行する
この手順を踏んだ結果、バージョンの内容は次のようになりました。
パッケージ | 古いバージョン | 新しいバージョン |
---|---|---|
firebase-functions | "^3.18.0" | "^4.2.0" |
firebase-functions-test | "^0.2.3" | "^3.0.0" |
そして、テストを実行した結果、上記で発生したエラーは発生しなくなりました。
念の為、エミュレーターを起動して今まで実行できるかを検証したところ、無事起動しました。
npm run build && firebase emulators:start --only firestore,auth,functions,storage