vscode-jest: node_modules/.bin/jest: line 16: exec: node: not found
Environment
vscode-jest version
:4.0.3
node -v
:14.17.3
npm -v
oryarn --version
:6.14.13
npm ls jest
ornpm ls react-scripts
(if you haven’t ejected):jest@27.0.6
- your vscode-jest settings if customized:
- jest.jestCommandLine?
node_modules/.bin/jest
- jest.autoRun?
{"watch": true, "onSave": "test-file", "onStartup": ["all-tests"]}
- anything else that you think might be relevant?
- jest.jestCommandLine?
- Operating system:
MacOS Big Sur
Prerequisite
- are you able to run jest test from the command line? yes
- how do you run your tests from the command line? (for example:
npm run test
ornode_modules/.bin/jest
)npm test
orpnpm test
Steps to Reproduce
After reload VS Code window, vscode-jest don’t auto run and stopped
Relevant Debug Info
node_modules/.bin/jest: line 16: exec: node: not found
Jest process "watch-tests" ended unexpectedly
see troubleshooting: https://github.com/jest-community/vscode-jest/blob/master/README.md#troubleshooting
Expected Behavior
vscode-jest auto run and launch all test
Actual Behavior
vscode-jest stop auto run
The fastest (and the most fun) way to resolve the issue is to submit a pull-request yourself. If you are interested, feel free to check out the contribution guide, we look forward to seeing your PR…
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 24 (2 by maintainers)
I had the same error due to my path in VS Code not having my NVM node directory in it (thanks @carlos-algms for the suggestion to check the
process.env.PATH
in the developer tools!).I fixed it by following these stackoverflow steps to make sure I had the correct path:
This issue is somewhat complicated due to there are many possible causes and also many ways they can be fixed. Let me first explain how we spawn the process, which, hopefully, will shed lights on the issues and solutions…
how do we start the jest run process?
It uses node child_process to spawn a jest process with a “non-interactive & non-login” shell, which basically mean it will inherit vscode process env(1) + maybe-shell-initialization(2)
Note, the current implementation uses the default shells specified by the node child_process (however this will be customizable in the upcoming release):
1. How does vscode initialize the process env?
You can read the first 3 paragraphs in this vscode doc. Basically depends on how you start vscode. It will do different things to try to make sure your environment is initialized with “.bashrc” or equivalent. However, sometimes this process might not succeed and you will end up in an incomplete environment, thus any subsequent jest process will be equally incomplete.
How do you verify this inherited env? Use the developer console log: For example, if you use nvm, your env should have NVM variables already configured: vscode-jest-env-log.gif
how to fix this issue ? There are many ways to fix this, for example:
source
command in your “jest.CommandLine” or scripts inpackage.json
, for examplesource abc.sh && jest
But why do vscode integrated terminals seem to work just fine? The terminal will launch an interactive & login shell, which will initialize the environment explicitly again. (see the initialization rules below)
2. How does an “non-interactive & non-login” shell got initialized?
Each shell might behave differently, you can read up on the following posts about how different types of shell starting types can impact the initialization:
It varied by shell. For example, by default, no initialization will occur unless you have
BASH_ENV
for bash orENV
for (Bourne) sh.Therefore, even the initial env is not complete as described above, the new shell spawned by the extension can still be correct if there is a proper initialization configured. However, if you decide to fix the env issue via this route, please note that adding initialization during each spawned shell might have performance overhead.
More help on the way…
We know it is frustrating… We are working on adding 2 new settings (in v4.2) that could hopefully make it easier to address this issue:
jest.nodeEnv
: users will be able to add env variables directly regardless of how the vscode or node initializes the envjest.shell
: allow users to pass their preferred shell instead of using the default shell, so you don’t have to maintain multiple env.Worth mentioning that for my case, restarting VSCode, which was started automatically after I logged into my machine, fixed the issue. Probably, when VSCode started, the
PATH
was not fully populated, but when a terminal is open, it will read all the environment variables, while a child process spawned will use the initially loaded variables.Try to open the developer tools and check for
process.env
at the console and double-check if all your variables are there.I have similar behavior. the command:
./node_modules/.bin/jest
works from the VSCode terminal, but not when set forjest.jestCommandLine
.My Error:
Worth mentioning that my Node is installed using NVM
The following in settings in the workspace settings i.e.
"${workspaceFolder}/.vscode/setting.json
, works for me:@carlos-algms restarting vscode worked for me too, but this problem still happens sometimes even when vscode wasn’t opened automatically
I believe another issue is if you launch via
code
in a terminal with the correct environment and then later you restart your system and it tries to relaunch windows it’ll launch vscode out of the previous expected context unfortunately.it hepls for me thx
Hello there !
Some updates regarding my problem :
As I use WSL and NVM, I decided to try to create a symlink from
/usr/bin/node
that sources/root/.nvm/versions/node/v15.5.1/bin/node
(as I usenode 12.5.1
). and it seems working.It would mean that the problem isn’t from WSL itself (I mean the fact that I use WSL in Windows isn’t the problem), I think it’s more due to the fact that when Jest invokes a shell to execute its commands, It do not invoke the shell as the user that openned VSCode. So your session’s file
~/.bashrc
or whatever you are using (bash, zsh …) is not read, so if you use NVM, the NVM path is not exported.