1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Cannot find module 'firebase-functions/lib/encoder' from ...というエラーが出た話

Posted at

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-functionsfirebase-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
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?