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

Does not find Node.js when using NVM on Ubuntu 22.04 LTS machine /bin/sh: 1: node: not found /bin/sh: 1: node: not found using VSCode Remote Explorer SSH. Finds Node.js on remote Ubuntu 22.04 LTS machine when not installed using NVM but unable to login to Ionic. Only able to use NVM and login to Ionic on local machine macOS Β #90

@ltfschoen

Description

@ltfschoen

i just started using an existing Ionic project https://github.com/svub/lets-stay-in-touch

i wanted to add instructions to that repos README file with the changes i'd made in this PR svub/lets-stay-in-touch#15 with the way i'd installed it on a fresh installation of Ubuntu 22.04 LTS that i am remotely accessing via SSH on Linode using the Remote Explorer SSH approach in VSCode.

I want to use remote machines because my local machine is an old 2 cpu macOS, and i do Rust programming where the compile time might be ~3 hrs on my local machine vs paying for a remote machine that'll compile it >10x faster. also shaves off time on some larger frontend projects.

  • Fork and clone the repository
  • Install NVM
  • Run nvm use (since it detects the .nvmrc file that contains v19.6.0 and automatically installs that version)
  • Install Node.js 19.6.0 via installing ) and running nvm use
  • Install dependencies and Yarn 3
yarn
corepack enable && corepack prepare yarn@stable --activate && yarn set version 3.4.1 \
yarn global add @ionic/cli@latest native-run cordova-res
  • Run the server
ionic serve

but then i discovered this Ionic Visual Studio (VS) Code Extension and realised it would a good workflow for debugging
so i installed the extension, clicked the Ionic icon, and clicked Login (i originally assumed it logged me in somehow, but it doesn't say it has or hasn't logged me in, and i later found out it should have redirected me to ionic.io/login to login, which it doesn't do), but then it displayed this error in the Visual Studio Code Ionic terminal:

[Error] /bin/sh: 1: npm: not found

then i clicked "Debug > Web" and it displayed the following in the Ionic terminal:

[Ionic] Running on Web...
> export ANDROID_HOME=~/Library/Android/sdk && npx ionic serve --external
/bin/sh: 1: npx: not found
[Ionic] export ANDROID_HOME=~/Library/Android/sdk && npx ionic serve --external Failed
[Ionic] Web Completed.

[Error] /bin/sh: 1: npm: not found

Sometimes it even says /bin/sh: 1: node: not found

Screen Shot 2023-02-24 at 2 10 29 pm

i searched the web for a solution
some suggested editting settings.json with CMD+ SHIFT + P > Preferences: Open Settings (JSON) and changing to:
"terminal.integrated.defaultProfile.linux": "sh", "terminal.integrated.profiles.linux": { "bash": { "path": "/bin/sh", "args": ["-l"] }, }
so i did that and restarted the VS code window but that didn't fix the error.
i tried adding the following to ~/.bash_profile too and then running source ~/.bash_profile, and repeated for ~/.profile but that still produced the same errors.

alias npx='/root/.nvm/versions/node/v19.6.0/bin/npx'

i tried running . ~/.nvm/nvm.sh but that didn't help either.

so i don't know how to configure the whatever PATH VSCode is using so it can find npx and npm.

but if i just install a version of Node.js using NodeSource without using NVM

curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

then restart VSCode, when i click the Ionic icon, and then press Login, it actually logs me in properly by opening my browser ionic.io/login, which i did and logged in, then clicked "Resend verification email", and verified it, and it logged me in
But VSCode still said "Complete the login in the web browser. This view will change as soon as you log in.", but that view still hadn't changed. So i logged out and logged back in in the browser but it still didn't update VSCode to log me in there too.
So i closed the VSCode window and opened it again, and clicked Login, and it automatically opened the browser at https://ionicframework.com/oauth/authorize?audience=https%3A%2F%2Fapi.ionicjs.com&scope=openid%20profile%20email%20offline_access&response_type=code&client_id=cli&code_challenge=<CHALLENGE_CODE>&code_challenge_method=S256&redirect_uri=http%3A%2F%2Flocalhost%3A8123&nonce=, and then continued to redirect to http://localhost:8123/?code= and displays error ERR_CONNECTION_REFUSED (i'm using latest Brave browser), and then it just showed the Sign Up or Login screen again in VSCode.

note: i've omitted the values that were shown for <CODE>, <CHALLENGE_CODE>, and <NONCE>

note that it opened http://localhost:8123/?code=, i was surprised that it didn't open http://<MY_REMOTE_IP_ADDRESS>:8123/?code=, since i wasn't working on my local machine....

so then i tried doing the same thing on my local machine to see if that'd work (slow old macOS). note: i don't actually want to work on my slow local machine

https://github.com/ltfschoen/lets-stay-in-touch
git fetch origin luke/setup:luke/setup
git checkout luke/setup
nvm use
yarn
corepack enable && corepack prepare yarn@stable --activate && yarn set version 3.4.1 \
yarn global add @ionic/cli@latest native-run cordova-res
code .

Then in VSCode i realised i had to install the ionic extension Ionic.ionic again for some reason.
Then i clicked the Ionic icon, and clicked Login, and it redirected me to http://localhost:8123/?code=, and then it displayed "You are authenticated!"

(i tried using that same code at the link http://<MY_REMOTE_IP_ADDRESS>:8123/?code= to try and login so i could use Ionic with VSCode with the Remote Explorer connect instead of my local machine but that didn't work)

And this time it actually logged me in, but then i realised i realised i hadn't updated to Yarn 3.4.1, and then i noticed i'd run yarn before running the command to update from Yarn 1 to Yarn 3, so i ran corepack enable && corepack prepare yarn@stable --activate && yarn set version 3.4.1 yarn global add @ionic/cli@latest native-run cordova-res and then yarn global add @ionic/cli@latest native-run cordova-res, but it gave error Usage Error: The 'yarn global' commands have been removed in 2.x, so i did yarn dlx @ionic/cli@latest native-run cordova-res install and that worked, and then ran yarn

then i opened VSCode and clicked Ionic icon > Debug > Web, and it compiled ok:

[Ionic] Debugging...
> export ANDROID_HOME=~/Library/Android/sdk && npx ionic serve --no-open --external
npm WARN exec The following package was not found and will be installed: ionic@5.4.16
npm WARN deprecated formidable@1.2.6: Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated superagent@4.1.0: Please upgrade to v7.0.2+ of superagent.  We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing.  See the releases tab for more information at <https://github.com/visionmedia/superagent/releases>.
npm WARN deprecated ionic@5.4.16: The Ionic CLI now uses ✨ @ionic/cli ✨ for its package name! πŸ‘‰ https://twitter.com/ionicframework/status/1223268498362851330
> npm run ionic:serve -- --host=0.0.0.0 --port=8100
[npm] > stay-in-touch@0.0.1 ionic:serve
[npm] > vue-cli-service serve --host=0.0.0.0 --port=8100
[npm]  INFO  Starting development server...
[INFO] Waiting for connectivity with npm...
[npm] [3%] setup (watch run)
...
[npm] [9%] setup (compilation ESLintWebpackPlugin_1)
[INFO] Development server running!
       
       Local: http://localhost:8100
       External: http://10.1.1.26:8100
       
       Use Ctrl+C to quit this process
[npm] [9%] setup (compilation)
...
[npm] [51%] building (108/329 modules)
...
[npm] Build finished at 16:06:22 by 0.000s
[npm] 
[npm]   App running at:
[npm]   - Local:   http://localhost:8100/ 
[npm]   - Network: http://10.1.1.26:8100/
...
[npm] Build finished at 16:06:23 by 0.000s
[npm] No issues found.

and it automatically opened localhost:8100 and worked great!

Metadata

Metadata

Assignees

Labels

potential bugLooks like a bug but requires confirmation / reproduction

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions