Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

The extension can't find node (due to use of nvm), and there's no setting to provide the path manually #101

Closed
1 of 4 tasks
darynmitchell opened this issue Dec 23, 2020 · 17 comments

Comments

@darynmitchell
Copy link

Describe the bug

  • extension load problem
  • test load missing suites/tests
  • test load errors
  • test running errors

A clear and concise description of what the bug is:

I don't have node installed directly, instead I use nvm.
node is available in my zsh shell path in vscode terminal:

$ which node
/home/foo/.nvm/versions/node/v14.15.3/bin/node

and

$ env node
Welcome to Node.js v14.15.3.
Type ".help" for more information.
>

However...

When the extension tries to load tests (i.e. initially l when I open the sidebar, or when I click 'Reload'), output displays error:

'/usr/bin/env: ‘node’: No such file or directory\n'

I added a log file to the Jest Test Explorer settings and it outputs:

[2020-12-23 02:31:24.190] [INFO] Loading Jest tests...
[2020-12-23 02:31:24.203] [INFO] Loading Jest settings from /home/foo/code/dailyservings/jest.config.js...
[2020-12-23 02:31:24.333] [ERROR] Error loading tests '/usr/bin/env: ‘node’: No such file or directory\n'
[2020-12-23 02:31:24.334] [INFO] Finished loading Jest tests.

To Reproduce
Steps to reproduce the behavior:

  1. Use nvm as your source for node, so node is not installed under /usr/bin/...
  2. Open the Test Runner sidebar
  3. See error

Expected behavior
Best: The extension should automatically use the node version that the project is already using
Workaround: The extension should provide a setting so I can manually set the path to node?

Desktop (please complete the following information):

  • OS: Windows host, VS Coe project open from Ubuntu 20 WSL2 container.

Additional context

  • In my zsh terminal shell, nvm is made available via zsh plugins+=(nvm)
  • Lots of people use nvm, I'm not sure why no one else was blocked by this same problem, could suggest problem on my end
  • Same issue with a different editor discussed (years ago) in usr/bin/env: node: No such file or directory  nvm-sh/nvm#786

    nvm only works from a shell session in which nvm.sh has been sourced. Within editors, this tends not to work well.

@cefn
Copy link

cefn commented Dec 30, 2020

In the case of nodenv (which I use in preference to nvm) I simply configure nodenv in a terminal, then launch VSCode from there, where it picks up the proper binary paths from the shell. This is on Ubuntu and bash, though.

@SplitThePotCyrus
Copy link

I'm using nvm and bash on Ubuntu and experience the same issue.

@rossknudsen
Copy link

Hey all.

The actual runner is in a depency (jest-editor-support). I think the issue is because the process runs in the default shell for your OS. Which I think is/bin/sh for you guys. I'm guessing the error you're experiencing is because your PATH doesn't include a directory to the location of node.js for your default shell.

Can you confirm whether this reasoning is correct? It would take a bit of effort to replicate this on my end.

@darynmitchell
Copy link
Author

darynmitchell commented Jan 25, 2021

Thanks for the question @rossknudsen

I think the issue is because the process runs in the default shell for your OS. Which I think is/bin/sh for you guys.

Although I am using zsh, it is configured as the default shell

$ echo $SHELL
/bin/zsh
$ grep "^$USER" /etc/passwd
myusername:x:1000:1000:,,,:/home/myusername:/bin/zsh

I also checked whether any other user has a different shell configured ("just in case"), and there is no other shell:

$ cat /etc/passwd | sed 's/^.*://' | sort | uniq
/bin/false
/bin/sync
/bin/zsh
/usr/sbin/nologin

So this makes me think the "default shell" part of the hypothesis might not be the case.

I'm guessing the error you're experiencing is because your PATH doesn't include a directory to the location of node.js for your default shell.

@rossknudsen this is the part of your hypothesis that I wonder if it could still apply to me. My nvm at the command line comes from loading the zsh nvm plugin in my .zshrc file. I must admit I don't know default shells well enough to know whether all processes get access to everything that .zshrc configures.

However, I'm still wondering about your case, @SplitThePotCyrus, as you mentioned bash on Ubuntu. That means it's for sure the default shell, right? — unless you changed default shell? And what about nvm, how/where did you install it?

@rossknudsen
Copy link

@darynmitchell have you tried the community Jest test extension? It uses the same dependency and I'm interested to know if that works under the same conditions.

@SplitThePotCyrus
Copy link

SplitThePotCyrus commented Jan 26, 2021

@darynmitchell

That means it's for sure the default shell, right?

Yes, it was my default shell.

However my main issue was: I created and ran a VM with Ubuntu.
I did not login via a standard terminal but rather used the Remote - SSH extension of VS Code and logged in. I then used the terminal (bash) inside VS Code to install nvm. Everything was working via VS Code then and node was in my path. As mentioned this extension was not work at this point, although everything else was working.

Then by accident, using an external terminal, I logged in (SSH) to the VM and noticed that nmv, node etc. was not working in that shell. It turns out that VS Code starts an interactive non-login shell, hence all paths etc. are added to ~/.bashrc when installed from terminal inside VS Code. The extension does not seem to use the same type of shell as VS Code is using, therefore was using a shell that looks at ~/.bash_profile (which was empty)

When I then added the following to my ~/.bash_profile, then the extension recognized my installed node and started working.

if [ -f $HOME/.bashrc ]; then
        source $HOME/.bashrc
fi

I think one hint to the issue might be that the extension is using other means of starting a shell than VS Code is currently using. Don't know if this helps in any way.

@rossknudsen
Copy link

The extension callschild_process.spawn passing in the option shell: true which then uses the "default" shell. Which seems to be missing node from the path. The source is here.

@rossknudsen
Copy link

I'm getting the feeling that the issue at hand here is more to do with machine setup, or the way you are running Code rather than the extension itself. Basically it appears that the PATH variable does not include the configured path to node and that is because nvm is not running when the Child_Process is being spawned - probably because the shell profile that should be executed, is not.

You could debug this if you want to, and I'm happy to provide guidance, but I'd either have to try and replicate your environment or guess. So, you could pull down the extension codebase, branch from master and add some debugging statements that would write out the value of process.env.PATH (it isn't that hard to do). Let me know if anyone wants to proceed down this path or not (pun intended).

@darynmitchell
Copy link
Author

Thanks for your questions @rossknudsen. I will look for an opportunity in my schedule (hopefully in the next two weekends) to give some time to trying again from scratch and update here on what I find.

@elsassph
Copy link

elsassph commented Feb 14, 2021

Do I have a related problem or should I raise a different issue?

On Mac, with "Path to Jest" set as npm run test (we use a custom configuration), the tests error with

'/bin/sh: ../../../../npm: No such file or directory\n'

@vviikk
Copy link

vviikk commented Mar 25, 2021

This is why I load nvm in my .profile instead of .bashrc or .zshrc. You avoid all these tiny pitfalls of 3rd party apps not finding node. Please try doing that and let me know if it works.

@JackStillwell
Copy link

After bashing my head against this wall on MacOS for the better part of a day, I just added the nvm node version bin to the path in the jest command line.

"jest.jestCommandLine": "\"PATH=$PATH:/Path/to/node/.nvm/versions/node/v.1.1.1/bin\"; npm run test --"

@RealDyllon
Copy link

This is why I load nvm in my .profile instead of .bashrc or .zshrc. You avoid all these tiny pitfalls of 3rd party apps not finding node. Please try doing that and let me know if it works.

This resolved the issue on MacOS 11 with zsh! Thank you!

@TheBrockEllis
Copy link

This is why I load nvm in my .profile instead of .bashrc or .zshrc. You avoid all these tiny pitfalls of 3rd party apps not finding node. Please try doing that and let me know if it works.

After updating to Mac OS Monterey, VS Code's debugger was giving us a We did not fine ‘node’ on your PATH… error when attempting to auto-attach to node processes. I can confirm that adding the NVM init lines to the .profile instead of the .zshrc file fixed it for us.

@orlein
Copy link

orlein commented Feb 8, 2022

This is why I load nvm in my .profile instead of .bashrc or .zshrc. You avoid all these tiny pitfalls of 3rd party apps not finding node. Please try doing that and let me know if it works.

You saved me!!

In addition,

Zsh is not hitting ~/.profile
(ref: https://superuser.com/questions/187639/zsh-not-hitting-profile)

So It is good for you to use like this when you are using zsh:

ln -s .profile .zprofile

(ref: https://superuser.com/a/901485)

You can handle .profile file for any other 3rd party apps.

Hope you all having happy testing with vscode-jest!

@ckifer
Copy link

ckifer commented Jan 12, 2024

None of this works in remote vscode when debugging. It works when running but debugging throws the error before anything else

@cafesanu
Copy link

in my case, in Linux machine this worked, but I imagine it would work for OSX as well:

ln -s /home/cs/.asdf/shims/node /usr/bin/node

Just replace /home/cs/.asdf/shims/node with wherever you node bin is located

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests