Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

"npx not found" when loading tests #33

Closed
chrismay opened this issue Jun 17, 2019 · 5 comments
Closed

"npx not found" when loading tests #33

chrismay opened this issue Jun 17, 2019 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@chrismay
Copy link

chrismay commented Jun 17, 2019

Describe the bug

On startup, the extension logs the following:

[13:43:04] INFO: Test Loading started...
[13:43:04] INFO: Starting Angular test enviroment for project: jasmine-config
[13:43:04] INFO: Listening to AngularReporter events on port 9999
[13:43:04] ERROR: stderr: /bin/sh: 1: npx: not found
  • and no tests are shown in the explorer view

Logs
Same error as above is visible in the console.

Desktop (please complete the following information):

  • OS: Code running on Windows 10, using remote SSH extension (ms-vscode-remote.remote-ssh) to run the language server and extensions on an Ubuntu box
  • Browser [e.g. chrome, safari] n/a
  • Angular Version [eg. 6.0.1] 7.3
  • Node version [eg. 6.0.1]11.15

npx is present:

$which npx
/home/ubuntu/.nvm/versions/node/v11.15.0/bin/npx

npx and node are both managed by nvm, so perhaps the problem is that nvm isn't being loaded when code runs whatever shell script is looking for it?

@chrismay chrismay added the bug Something isn't working label Jun 17, 2019
@Raagh
Copy link
Owner

Raagh commented Jun 17, 2019

Hey @chrismay thanks for reporting the issue, I will do my best to help you out.

The command is trying to run is "npx ng test" which will be basically running angular ng test but with the local dependency. This is done because your system doesn't have the angular cli installed globally, only locally in the project folder.

what happens if you go the root folder of the project with the command line and use the command "npx ng test" ? does karma starts?

@chrismay
Copy link
Author

Hi, thanks for getting back so quickly!

npx runs fine from a logged-in bash/zsh session:

$ npx ng test
 10% building 2/2 modules 0 active ...                                          

however, if I run with a clean environment, it does not:

$ env -i sh 
$ npx
sh: 1: npx: not found
$ 

This is because node/npx/ng etc aren't on the path by default; the nvm utility adds them to the path when it runs. Presumably, whatever process is starting the npx command from within the extension isn't aware of nvm.

Can you point me to where in the extension code you start npx? I can take a look and see if there's an easy way to get it to run my .bashrc (which will set up nvm ) before trying to run npx.

@Raagh
Copy link
Owner

Raagh commented Jun 17, 2019

Hi, yes sure. the angular process is start in this line and here

and the commands are setup a lil before here

please let me know if there is anything else I can do to help you. To be honest I will have to do some investigation myself to solve this as I don't have knowledge on the subject.

If you know how to fix it please feel free to submit a pull request :)

@chrismay
Copy link
Author

Hmm; I think it's going to be difficult to do this in a way that works reliably.

When VS code remote extensions start up on the server, they don't have any knowledge of the users' .bashrc configuration. So tools like nvm, which modify your path after login, are invisible to them; there's no way (other than sniffing around the ~/.nvm directory) for the extension to know which node version the user has selected to use.

I think the easiest fix for me right now is just to install the desired version of node and npx directly on my remote server, rather than using nvm. Since this server is set up automatically, and dedicated to a specific project, there's no particular benefit to being able to swap between different node implementations.

An alternative, if someone really wanted to use nvm, might be to have a configuration setting for the user to specify the path to their node installation (e.g. ~/.nvm/versions/${version}/bin/node), and if that variable is set, invoke karma with a command line something like ${node_binary} node_modules/@angular/cli/bin/ng test ....etc.. -

But that sounds like a lot of work, when the alternative is for me to stop being difficult and just do 'apt install nodejs' like a normal person 😀 "

@Raagh
Copy link
Owner

Raagh commented Jun 18, 2019

Ahaha I totally get it, please let me know if everything works as expected when you install node in the server. I am gonna close this bug and create a feature request for the node installation path. Sounds as a good idea to me for anyone that really needs that option you mentioned. I will get to it when I finish with the current feature requests.

Again thanks for coming up with a definition of the problem and solution for this. I am not familiar with this type of setup.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants