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?

WSL2 + Docker + VSCode の Jest 拡張でテストが失敗する

Posted at

WSL2 + Docker + VSCode の Jest 拡張でテストが失敗する

Could not resolve a module for a custom reporter の直し方

症状

WSL2 上の Docker コンテナに VSCode から接続し、
VSCode 拡張機能「Jest」でテストを実行すると失敗する。

Error: Could not resolve a module for a custom reporter.
Module name: /root/.vscode-server/extensions/orta.vscode-jest-6.4.4/out/reporter.js

一方で、ターミナルからの実行は成功する。

  • ✅ npm test → 成功
  • ❌ VSCode の Jest 拡張 → 失敗

結論(対処)

.vscode/settings.jsonjest.jestCommandLine を設定すると解決する。


環境

  • Windows
  • WSL2
  • Docker
  • VSCode
  • VSCode 拡張機能:Jest
  • Jest は node_modules にインストール済み

原因

VSCode の Jest 拡張が、
コンテナ内で Jest を実行する際のパス解決に失敗している。

そのため、拡張機能が用意する custom reporter
(/root/.vscode-server/.../reporter.js) を解決できずエラーになる。


手順

settings.json(Windows / WSL 混在を避けたい場合)

プロジェクト直下に .vscode/settings.json を作成(または追記)する。

{
  "jest.jestCommandLine": "node node_modules/jest/bin/jest.js"
}

動作確認

  • VSCode の Jest 拡張からテストを再実行
  • エラーが出ず、テストが流れれば OK

注意点

  • Jest が node_modules に存在することが前提
  • この設定は ワークスペース単位で有効

まとめ

  • custom reporter のエラーだが、原因は Jest の実行方法
  • WSL2 + Docker 環境では VSCode の Jest 拡張が誤動作することがある
  • jest.jestCommandLine を明示すると解決する
  • Windows / WSL 混在環境では
    node node_modules/jest/bin/jest.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?