0
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?

Jest が firebase のライブラリに対して Cannot find module ... と出してくる際の対処法

Last updated at Posted at 2024-06-26

何があったか

あるTypescriptのテストでfirebaseのライブラリを使っていると、Jestでテストを回したときに以下のようなエラーが出る。

  ● Test suite failed to run

    Cannot find module 'firebase-admin/app-check' from 'node_modules/firebase-functions/lib/common/providers/https.js'

    Require stack:
      node_modules/firebase-functions/lib/common/providers/https.js
      node_modules/firebase-functions/lib/common/providers/identity.js
      node_modules/firebase-functions/lib/v1/providers/auth.js
      node_modules/firebase-functions/lib/v1/index.js
      ...

      at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
      at Object.<anonymous> (node_modules/firebase-functions/lib/common/providers/https.js:29:21)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        3.248 s

解決方法

jest.config.jsにmoduleNameMapperを設定してあげるとpathの依存が解決する。

functions/jest.config.js
moduleNameMapper: {
    "^firebase-admin/(.*)$": "<rootDir>/node_modules/firebase-admin/lib/$1/index.js",
  },

参考記事

0
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
0
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?