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?

【Jest】テスト時にReferenceError: module is not defined in ES module scopeエラーが出た

Last updated at Posted at 2025-08-31

はじめに

Jestでテストした時に「ReferenceError: module is not defined in ES module scope」とエラーが出てテストが通らなかったので、その解決方法についてまとめます。

気づき

解決策として「babel.config.js」のファイル名を「babel.config.cjs」に変更することで上記エラーは解決しました。

この要因について、JestではCommonJS(CJS)を前提としているため、ECMAScriptモジュール(ESM)のサポートを実験的に提供しているが、その実装にはバグや機能の欠如がある可能性があると警告されています。

参考
https://archive.jestjs.io/docs/ru/next/ecmascript-modules?utm_source=chatgpt.com

おわりに

テストにおいてもコードの内容だけでなく、サポートいついても気をつけなくてはいけないことが学びになりました。

JISOUのメンバー募集中!

プログラミングコーチングJISOUでは、新たなメンバーを募集しています。

日本一のアウトプットコミュニティでキャリアアップしませんか?

興味のある方は、ぜひホームページをのぞいてみてくださ!

▼▼▼

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?