Operating system and version:
nvm debug output:
rockchalkwushock in mashaeltsova-photography on development [+?] $ nvm debug
nvm --version: v0.33.6
$TERM_PROGRAM: vscode
$SHELL: /bin/bash
$HOME: /Users/rockchalkwushock
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)'
uname -a: 'Darwin 17.0.0 Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64 x86_64'
OS version: Mac 10.13 17A405
curl: /usr/bin/curl, curl 7.54.0 (x86_64-apple-darwin17.0) libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0
wget: not found
git: /usr/local/bin/git, git version 2.14.3
grep: /usr/bin/grep, grep (BSD grep) 2.5.1-FreeBSD
awk: /usr/bin/awk, awk version 20070501
sed: illegal option -- -
usage: sed script [-Ealn] [-i extension] [file ...]
sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
sed: /usr/bin/sed,
cut: illegal option -- -
usage: cut -b list [-n] [file ...]
cut -c list [file ...]
cut -f list [-s] [-d delim] [file ...]
cut: /usr/bin/cut,
basename: illegal option -- -
usage: basename string [suffix]
basename [-a] [-s suffix] string [...]
basename: /usr/bin/basename,
rm: illegal option -- -
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
rm: /bin/rm,
mkdir: illegal option -- -
usage: mkdir [-pv] [-m mode] directory ...
mkdir: /bin/mkdir,
xargs: illegal option -- -
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
[-L number] [-n number [-x]] [-P maxprocs] [-s size]
[utility [argument ...]]
xargs: /usr/bin/xargs,
nvm current: v8.8.1
which node: $NVM_DIR/versions/node/v8.8.1/bin/node
which iojs:
which npm: $NVM_DIR/versions/node/v8.8.1/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v8.8.1
npm root -g: $NVM_DIR/versions/node/v8.8.1/lib/node_modules
nvm ls output:rockchalkwushock in mashaeltsova-photography on development [+?] $ nvm ls
-> v8.8.1
default -> node (-> v8.8.1)
node -> stable (-> v8.8.1) (default)
stable -> 8.8 (-> v8.8.1) (default)
iojs -> N/A (default)
lts/* -> lts/boron (-> N/A)
lts/argon -> v4.8.5 (-> N/A)
lts/boron -> v6.11.5 (-> N/A)
rockchalkwushock in mashaeltsova-photography on development [+?] $
nvm? (e.g. install script in readme, homebrew):install_scriptcurl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
# inside .bash_profile
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
source .bashrc
nvm install node
nvm use node
git using husky & lint-staged I am getting the following output:nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"
Run `unset PREFIX` to unset it.
Found '/Users/rockchalkwushock/Desktop/MEP/mashaeltsova-photography/.nvmrc' with version <8.8.1>
nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"
Run `unset PREFIX` to unset it.
Found '/Users/rockchalkwushock/Desktop/MEP/mashaeltsova-photography/.nvmrc' with version <8.8.1>
nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"
Run `unset PREFIX` to unset it.
.git/hooks/pre-commit: line 49: node: command not found
husky > npm run -s precommit (node )
env: node: No such file or directory
husky > pre-commit hook failed (add --no-verify to bypass)
/Users/rockchalkwushock/Desktop/MEP/mashaeltsova-photography/node_modules/commitizen/dist/cli/strategies/git-cz.js:102
throw error;
^
Error: git exited with error code 1
at ChildProcess.<anonymous> (/Users/rockchalkwushock/Desktop/MEP/mashaeltsova-photography/node_modules/commitizen/dist/git/commit.js:50:26)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
The script called "commit" which runs "git cz" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.7.1/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Commit and push up as I have been doing with no issues. Had zero problems on Saturday. No updates were ran in between then and now. I have since upgraded nvm from 0.33.4 to 0.33.6 and upgraded node 8.8.0 to 8.8.1. git has always been installed with homebrew and has caused me not issues before when working with nvm.
.bashrc, .bash_profile, .zshrc, etc) that modifies the PATH?PATH=/Users/rockchalkwushock/.nvm/versions/node/v8.8.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/rockchalkwushock/.config/yarn/global/bin
# in .exports
# Set Yarn Global Binary Path.
export PATH="$PATH:`yarn global bin`";
I need to keep moving on this project so I am bypassing the use of git-cz and just running git commit The following was output:
rockchalkwushock in mashaeltsova-photography on rework [+] $ git commit -m "Begin Rework"
Found '/Users/rockchalkwushock/Desktop/MEP/mashaeltsova-photography/.nvmrc' with version <8.8.1>
Now using node v8.8.1 (npm v5.4.2)
Found '/Users/rockchalkwushock/Desktop/MEP/mashaeltsova-photography/.nvmrc' with version <8.8.1>
Now using node v8.8.1 (npm v5.4.2)
husky > npm run -s precommit (node v8.8.1)
Should nvm be running outputting that twice? At any rate I can commit and keep going on this project.
The issue is that something was setting the PREFIX environment variable; if git-cz is doing that, then that's where the issue needs to be filed.
As for the nvm output, if your precommit hook is sourcing nvm.sh twice (perhaps by invoking multiple login shells, instead of doing it all in one go), then the output is expected - if you share the code for your precommit hook, I can take a look at it.
Either way tho this isn't actionable for nvm itself, so I'm going to close the issue (but we can of course keep discussing)
Not really sure why this was closed as it is clearly still an issue.
100% default system here, I just bought a new iMac pro... XCode then this was my first installations. I have installed nvm many times on other systems and now I run into this...
Nothing in my files or setup that could possibly set PREFIX so its being done somewhere invisible to me
Last login: Sun Mar 11 21:20:45 on ttys008
nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"
Run `unset PREFIX` to unset it.
Bradens-iMac-Pro-2:~ bradennapier$
with my .bashrc
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
and my .bash_profile
source ~/.bashrc
I have reinstalled nvm, i have tried everything. I have never installed node on the system.
This appears to happen by doing a npm install -g ____ as a default issue
Perhaps Node 9.8.0 uses PREFIX?
I literally have no idea how that is set but i have about 100 env vars set by default in terminal seemingly by XCode
I would also point out that OSX's default Terminal.app does not work however iTerm does work.
Since this is being launched by react-native - it does appear it might be related to that in some way?
https://github.com/expo/expo/issues/626
Not really sure it works sometimes but not others at this point
@bradennapier Seems like Xcode launching Terminal from /usr/local, but your nvm has been installed and located in your user's folder.
I too have this issue, and my personal finding is that it is related to using an alias (nvm use ALIAS) instead of the version (nvm use VERSION).
For example, nvm use --lts doesn't work but nvm use v8.11.2 does work (same version --lts points to). It has the same behavior with custom/built-in aliases.
@JBallin thanks, that's helpful - can you file a new issue, and fill out the issue template, and include that info?
@ljharb Will do!
I had this issue trying to use nvm in Termux, which is a prefixed Linux environment for Android.
I got around it by running:
PREFIX= nvm use --delete-prefix stable
This didn't unset the PREFIX environment variable, or even delete the prefix npm config (npm config get prefix still returns the old prefix), but it did let nvm run properly.
@goodevilgenius note that that will cause nvm to not actually work properly - which is the reason that the prefix is blocked in the first place. Why is the prefix needed?
@ljharb The prefix is needed in Termux. It's a Linux environment made to work on top of an existing version of Android. It's not a chroot, and since it's made to work without root access, it must be installed within a directory to which it has write permissions, thus the need for the PREFIX. The entire system (apt, coreutils, the home directory, etc.) are installed into the app's data directory.
I can install node as usual through apt, and it works fine. But nvm fails because of the PREFIX.
@goodevilgenius PREFIX is used to change the location of npm root -g. When using nvm, that lives inside $NVM_DIR - which is inside that directory. Thus, you should not, in fact, need PREFIX for node when using nvm under any circumstances. (separately, don't install node via apt, and if you insist on doing so, use the nodesource repo)
@ljharb That's fine for nvm, but I'm saying that I have to have PREFIX set when using Termux, otherwise other apps won't work properly. It's just the way Termux was built.
So, by doing PREFIX= nvm use --delete-prefix stable, it basically unset PREFIX only for nvm. npm and npx then worked after that, although node did not.
But, I can't just add unset PREFIX in my .bashrc and use everything as usual. Everything else will break.
@goodevilgenius ohhh i gotcha, it's a collision in the environment variable name :-( that's very unfortunate. The problem is that PREFIX will also change how npm works - so that kind of sounds like Termux is simply incompatible with node/npm, tbh.
node/npm work fine in Termux when installed from apt, just not when installed from nvm.
@goodevilgenius npm root -g will be whatever's in $PREFIX; that's still impacting npm even if it ends up working. nvm is incompatible with having a prefix, so it seems like Termux is, at the moment, incompatible with nvm.
Please file a separate issue for tracking Termux specifically.
@ljharb I made a mistake here, my issue was specifically with husky (putting the right input formats) and I blamed it on nvm, sorry!
Having the same issue. With no solution at all
I uninstalled Termux and the issue went away so there's definitely a conflict that needs to be worked out.
@goodevilgenius I have the same problem, is there new resolution pls?
@luxueyan I never found a solution. I just installed node from apt, instead of using nvm.
@goodevilgenius I鈥檇 be happy to help if you filed a separate issue; node shouldn鈥檛 be installed from apt.
@ljharb What would be the point of creating a separate issue? This issue already states the problem. You said:
nvm is incompatible with having a prefix, so it seems like Termux is, at the moment, incompatible with nvm.
Termux isn't going to stop using a PREFIX, as it's necessary to their implementation on Android, and nvm isn't going to support an environment with PREFIX, or this issue wouldn't have been closed, so as far as I can tell, ne'er the twain shall meet.
Ah, fair enough.
@goodevilgenius Now my resolution is installing a ubuntu using atilo:https://github.com/YadominJinta/atilo and then install nvm in ubuntu.
Agree that this appears to be an actual issue.
Could a possible solution be to use a more specific environment variable name instead of PREFIX? Something like NVM_PREFIX, which would make collisions much less likely
@mjumbewu no, unfortunately it's node itself that uses "PREFIX", and the nature of a node version manager is that it needs to own the prefix location, so there's simply no working around it.
In other words, if both Termux and node aren't going to change, then Termux just isn't compatible with using a node version manager. I'm still not clear on why Termux couldn't change the name of their env var - is there an issue on their project I could read about it?
FYI, I am having this issue with any regular MacOS terminal now. I am using react native as someone posted before and my PREFIX variable returns '/usr/local'. Not sure which tool is setting it now. @goodevilgenius workaround worked for me tho.
Most helpful comment
I had this issue trying to use
nvminTermux, which is a prefixed Linux environment for Android.I got around it by running:
This didn't unset the
PREFIXenvironment variable, or even delete theprefixnpm config (npm config get prefixstill returns the old prefix), but it did letnvmrun properly.