VSCode の Jest 拡張機能での Jest の起動に失敗する場合

環境

  • Windows (WSL2)
  • Node のバージョン管理には nodenv を使用している

状況

具体的には以下のようなエラーがターミナルに出るときです。

/usr/bin/env: 'node':そのようなファイルやディレクトリはありません
Jest process "watch-tests" ended unexpectedly
see troubleshooting: https://github.com/jest-community/vscode-jest/blob/master/README.md#troubleshooting

gyazo.com

結論

~/.vscode-server/server-env-setup というテキストファイルを作り*1、以下の内容を書いて保存する。

保存したあとは VSCode を再起動する。

export PATH="$HOME/.nodenv/bin:$PATH"
eval "$(nodenv init -)"

参考

以下の Issue がまさにこの現象に関する Issue です。

github.com

*1:Insiders バージョンを使用している場合は ~/.vscode-server-insiders/server-env-setup

Powered by はてなブログ