React-Native env: node: No such file or directory - xcode

I'm getting the following build error when compiling my react-native project in Xcode env: node: No such file or directory
Not sure whats causing it?
Node v8.9.4
React-Native v0.50.4
NPM v5.6.0
And I'm using nvm

if you are using nvm do
sudo ln -s "$(which node)" /usr/local/bin/node
this will link current nvm to your usr local and next time Xcode will find the correct node path and version

Xcode have some issues finding node from nvm, try this inside the script that throws the error:
# Setup nvm and set node
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
. "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
. "$(brew --prefix nvm)/nvm.sh"
fi
[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"
$NODE_BINARY ../node_modules/#sentry/cli/bin/sentry-cli upload-dsym

Here is one of the solutions for this error if you're using nvm and sentry: https://docs.sentry.io/clients/react-native/manual-setup/#using-node-with-nvm

In my case, this was related to an old sentry configuration and the fact that I use nvm.
Following https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/
you should be able to execute ln -s $(which node) /usr/local/bin/node and get it fixed

Add this at the top of the script that's failing (in Project -> build phases):
. ~/.nvm/nvm.sh

The solution I used documented here, was to create a script at /usr/local/bin/node that calls nvm
#!/usr/bin/env sh
# Use the version of node specified in .nvmrc to run the supplied command
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh" # This loads nvm
nvm_rc_version > /dev/null 2> /dev/null
HAS_NVM_RC=$?
if [[ "$HAS_NVM_RC" == "0" ]] ; then
nvm run $*
else
nvm run default $*
fi
exit $?

Related

How to programmatically install nvm and install / use npm?

SO...
I have created some scripts to help configure my shell, but I am having an issue with nvm. My script looks like...
#!/bin/zsh
set -Eeuo pipefail
echo 'Installing nvm'
touch $HOME/.zshrc
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | zsh
echo 'Setting default'
echo 'stable' > $HOME/.nvmrc
echo 'Installing default'
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install
nvm use
...but I am getting...
N/A: version "stable -> N/A" is not yet installed.
You need to run "nvm install stable" to install it before using it.
...but when I run nvm install on my terminal, it works as expected. I tried wrapping nvm install with eval(), $(), but nothing seems to work, what am I missing? Any help is much appreciated!
Answer provided by #l3l_aze!
set -E at the top of the shell script was the culprit, so I changed my script to be...
#!/bin/zsh
set -euxo pipefail
...and it works!

How to use lxc exc to issue multiple commands as specific user

My goal is to execute two commands in a specific folder as ubuntu from outside of it's lxc container.
I've tried a couple of things but I figured this example is the closest I have to working.
If I run
root#host$ lxc exec my-containter -- sudo --login --user ubuntu eval "cd /home/ubuntu/mydir && pwd && whoami && env && npm install && echo done"
I get an npm install error that can't find some module, but it looks like I'm the right user
However if I manually do it as two steps it does work... but I'm trying to put this in a bash script, so that I can keep doing operations on the host, so I think I need it as one.
root#host$ lxc exec my-containter -- sudo --login --user ubuntu
ubuntu#my-container$ eval "cd /home/ubuntu/mydir && pwd && whoami && env && npm install && echo done";
I discovered that my PATH environment variable is different in these two situations, the one that is failing is missing a specific path for nvm/npm. I tried exporting it during the eval command, but it seems like the resources available to me have already been found? What could I do to make the PATH variable populate the same way in the single line scenario?
PATH from 1-line (non-interactive)
PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin:/home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/snap/bin
PATH from 2-lines (interactive)
PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin:/home/ubuntu/.nvm/versions/node/v8.9.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
I've also noticed this nvm code at the bottom on my .bashrc file. From what I've read it sounds like the .bashrc file only gets executed in interactive mode.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
The below command should do the job for you
lxc exec my-containter -- sudo --login --user ubuntu bash -ilc "cd /home/ubuntu/mydir && pwd && whoami && npm install && echo done"
The .bashrc file has below at the top
case $- in
*i*) ;;
*) return;;
This code prevents the rest of the part of .bashrc to be executed in case of a non-interactive bash. So to make it interactive you should add the -i flag

Bash check if nvm installed

How can I detirmine if nvm (Node Version Manager) is installed in bash?
I already have it installed in my system but I haven't been able to make any bash script that can detect it. I am making a script that should be used by others which depends on nvm, so I want to output if it's not installed and exit if it isn't..
This doesn't work: https://stackoverflow.com/a/26759734/846348 it says that nvm isn't installed but the bash script can use nvm..
Would be nice if it supported Mac Terminal, Mac iTerm and Windows with Linux shell at least.
one can check with command -v nvm:
$ command -v nvm >/dev/null 2>&1 || { echo >&2 "nvm is required, but it's not installed. Aborting."; exit 1; }
The nvm install script checks if nvm is installed using roughly the following logic:
if [ -d "${HOME}/.nvm/.git" ]; then echo "nvm installed"; else echo "nvm not installed"; fi
This just checks if the directory ~/.nvm/.git exists.
To exit with failure if the directory ~/.nvm/.git does not exist, you could use:
if [ ! -d "${HOME}/.nvm/.git" ]; then exit; fi
Check if nvm installed using a Makefile
NVM_EXISTS := $(shell if [ -d "${HOME}/.nvm/.git" ]; then echo "nvm installed"; fi)
.PHONY: check
check:
ifndef NVM_EXISTS
$(error Please install nvm: https://github.com/nvm-sh/nvm)
endif
Note on nvm install.sh
The actual install script uses the following functions to determine the nvm installation directory (rather than assuming ${HOME}/.nvm). But if you are using the default location ${HOME}/.nvm, you can skip these checks.
nvm_default_install_dir() {
[ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm"
}
nvm_install_dir() {
if [ -n "$NVM_DIR" ]; then
printf %s "${NVM_DIR}"
else
nvm_default_install_dir
fi
}

Bash file working on local computer but not working on Amazon EC2 instance

I have a simple bash file which fixes the npm permission on my system. It goes like this
npm=`npm config get prefix`
echo "$npm"
if [[ $npm = "/usr/local" ]]
then
echo "Yes it's /usr/local"
echo $npm/{lib/node_modules,bin,share}
sudo chown -R $(whoami) $npm/{lib/node_modules,bin,share}
echo "Complete"
elif [[ $npm = "/usr" ]]
then
echo "Uhhohh it's /usr gotta use a different method"
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
echo "No"
fi
npm install -g forever
npm install -g pm2
npm install -g bower
This works fine on my machine. But not my amazon ex2 instance. I am running ubuntu 16.04 LTS on my AWS EC2 instance and Ubuntu 15.04 on my local system. The error which I get is npm-permission.sh: line 2: =/usr: No such file or directory
Which is the second line. What is the issue? Why doesn't it work?
So a change as suggested by #Cyrus in the comments I modified the script to have if [[ $npm = '' ]] which made it work. Here is the working script.
npm=$(npm config get prefix)
echo "$npm"
if [[ $npm = "/usr/local" ]]
then
echo "Yes it's /usr/local"
echo $npm/{lib/node_modules,bin,share}
sudo chown -R $(whoami) $npm/{lib/node_modules,bin,share}
echo "Complete"
elif [[ $npm = "/usr" ]]
then
echo "Uhhohh it's /usr gotta use a different method"
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo "export PATH=~/.npm-global/bin:$PATH" >> ~/.profile
source ~/.profile
echo "No"
fi
I still don't know how it works, but it does. Some bash expert might throw some light on it.

command not found: complete

I have a fresh mac in front of me, I installed homebrew (just fine), and oh my zsh (just fine).
I'm trying to install autojump which is a intelligent database of directories. For example, you can 'jump' to ~/Documents with j doc in terminal.
I did this
brew install autojump
I already have my .zshrc that looks fine I think. I added the line into it that it said:
[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
When I start iterm2 I get the following warning:
/usr/local/Cellar/autojump/21.3.0/etc/autojump.bash:13: command not found: complete
/usr/local/Cellar/autojump/21.3.0/etc/autojump.bash:55: = not found
I have used brew to install other things, and I can run autojump -s successfully so I know it is seeing the $path. I don't know what else could be wrong though, as this is all a fresh install.
In your .zshrc, you must source autojump.zsh, not autojump.bash
(I do not know where it will be located on a Mac, but it will be in same folder as autojump.bash).
On Ubuntu, here is what you need to append at the end of your .zshrc:
source /usr/share/autojump/autojump.zsh
To fix the problem, you should update the line:
[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
to say:
[[ -s `brew --prefix`/etc/autojump.zsh ]] && . `brew --prefix`/etc/autojump.zsh
i.e. use the .zsh version of the autojump script. That fixed it for me.
That file has no Shebang. This means that it is probably getting interpreted by Zsh.
This is a problem because complete is a Bash builtin.
Perhaps this can be a fix for you, or maybe
[[ -s `brew --prefix`/etc/autojump.sh ]] && bash `brew --prefix`/etc/autojump.sh
In my case, comment out
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
solved the issue.
You need to add
[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
to your ~/.bash_profile. Homebrew tells you this when you install but I didn't notice it the first time and came to this webpage as a result.
In my case, I solve this issue adding :
autoload bashcompinit && bashcompinit
Before the first complete command.
I've used this link : Fixed! az.completion:10: command not found: complete
If you are mac user using .zsh
just add the following to your .zsrc file
autoload -U +X bashcompinit && bashcompinit
autoload -U +X compinit && compinit
for more info refer to link : https://github.com/eddiezane/lunchy/issues/57

Resources