Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NVM is not compatible with the npm config "prefix" option warning (Mac OS) + npm ERR! code ELIFECYCLE npm ERR! errno 11 npm ERR! Exit status 11 #1873

Closed
sbarrett08 opened this issue Jul 24, 2018 · 60 comments
Labels
needs followup We need some info or action from whoever filed this issue/PR.

Comments

@sbarrett08
Copy link

sbarrett08 commented Jul 24, 2018

  • Operating system and version:
    MAC OS High Siera 10.13.4
  • nvm debug output:
nvm --version: v0.33.11
$TERM_PROGRAM: Apple_Terminal
$SHELL: /bin/bash
$SHLVL: 1
$HOME: /Users/scottbarrett
$NVM_DIR: '$HOME/.nvm'
$PATH: $NVM_DIR/versions/node/v9.8.0/bin:/usr/local/apache-maven-3.3.9/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
$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.5.0 Darwin Kernel Version 17.5.0: Mon Mar 5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64'
OS version: Mac 10.13.4 17E199
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.8.1
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: v9.8.0
which node: $NVM_DIR/versions/node/v9.8.0/bin/node
which iojs: 
which npm: $NVM_DIR/versions/node/v9.8.0/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v9.8.0
npm root -g: $NVM_DIR/versions/node/v9.8.0/lib/node_modules
  • nvm ls output:
        v6.11.1
->       v9.8.0
         system
node -> stable (-> v9.8.0) (default)
stable -> 9.8 (-> v9.8.0) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.3 (-> N/A)
lts/carbon -> v8.11.3 (-> N/A)

command -v nvm

added to 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

  • What happened?
    I'd had some node/npm permissions issues due to a local node install in the root directory. Removed that and then got nvm to avoid the issues going forward. When trying to run some scripts in a project to restore a mongoDB schema which was working fine until this point i'm now getting the following error:
nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/Users/scottbarrett/.nvm/versions/node/v9.8.0"
Run `unset npm_config_prefix` to unset it.
npm ERR! code ELIFECYCLE
npm ERR! errno 11
npm ERR! Exit status 11

running unset npm_config_prefix has no impact, have also removed the prefix from the ~/.npmrc file in case a preset issue existed.

  • What did you expect to happen?

I expected the DB to restored as normal with no npm/nvm errors

  • Is there anything in any of your profile files (.bashrc, .bash_profile, .zshrc, etc) that modifies the PATH?

Yes:

export PATH=/usr/local/apache-maven-3.3.9/bin:$PATH
@sbarrett08 sbarrett08 changed the title NVM is not compatible with the npm config "prefix" option warning (Mac OS) NVM is not compatible with the npm config "prefix" option warning (Mac OS) + npm ERR! code ELIFECYCLE npm ERR! errno 11 npm ERR! Exit status 11 Jul 24, 2018
@ljharb
Copy link
Member

ljharb commented Jul 24, 2018

The prefix definitely needs to be deleted fro the npmrc file; other than that, what happens (without nvm) if you run npm ls -g --depth=0, or npm config get prefix?

@ljharb ljharb added the needs followup We need some info or action from whoever filed this issue/PR. label Jul 24, 2018
@sbarrett08
Copy link
Author

sbarrett08 commented Jul 24, 2018

I've removed the prefix entirely from the npmrc file, this now tracks node versions correctly when switching between versions via nvm

npm ls -g --depth=0 returns:

/Users/scottbarrett/.nvm/versions/node/v10.7.0/lib └── npm@6.1.0

npm config get prefix returns:

/Users/scottbarrett/.nvm/versions/node/v10.7.0

@ljharb
Copy link
Member

ljharb commented Jul 24, 2018

Sounds resolved; happy to reopen if not.

@ljharb ljharb closed this as completed Jul 24, 2018
@sbarrett08
Copy link
Author

sbarrett08 commented Jul 25, 2018

Yeah @ljharb please could this be reopened as still getting the issue

@ljharb
Copy link
Member

ljharb commented Jul 25, 2018

@sbarrett08 sure!

so with the prefix removed, you're still having trouble running nvm use?

@ljharb ljharb reopened this Jul 25, 2018
@sbarrett08
Copy link
Author

It's not running nvm use that causes the issue, i can nvm use to switch or run any node version, however when i run some prebuilt npm commands which were working successfully previously i get the errors about the config prefix incompatibility and the npm error code 11.

Fairly certain it's not my npm commands or bash scripts that are the cause as they are basically just bash script commands which all work fine using independent execution. There are commands which execute a bash script && another npm command with the other npm command itself just being another bash script. The issue deffo seems to be around nvm/npm and this config prefix

@ljharb
Copy link
Member

ljharb commented Jul 25, 2018

ahhh - if you're running a bash script, it has to either inherit the PATH or re-source nvm itself. Can you elaborate on exactly what commands you're running, from the command line (where nvm's node is available)?

@sbarrett08
Copy link
Author

sbarrett08 commented Jul 26, 2018

Yes for example we have one command

  1. npm run restore-db which in the package.json equates to bash scripts/dbImport.sh && npm run test-dbSetup

npm run test-dbSetup consists of bash scripts/dbImport.sh <params> followed by two params for folder/schema/collection

I can run the bash scripts/dbImport.sh independently and the npm run test-dbSetup command independently, but the combination as at 1. results in the npm error, there are many other commands we have result in the same error

@ljharb
Copy link
Member

ljharb commented Jul 26, 2018

dbImport.sh probably has to source nvm.sh itself - otherwise it won't inherit the PATH (which is how node comes in)

@ljharb
Copy link
Member

ljharb commented Jul 26, 2018

Can you share the contents of dbImport.sh?

@sbarrett08
Copy link
Author

Forgive my ignorance in these areas i'm a junior and still trying to pick things up in respect of node etc. that script makes no reference to nvm.sh that i can see but are you saying that because of the script being called via npm it would need something additional to enable it to execute? The only source the script goes to in terms of contents is the bash profile to pick up some db params for host, port, username, pwd etc, should there be something else in the bash profile regarding the Path?

In the package.json i have an alias for some commands, these two aliases for example are combined into one command restore-db

  1. "restore-db": "bash scripts/dbImport.sh && npm run test-dbSetup"
  2. "test-dbSetup": "bash scripts/dbImport.sh param1 param2"

I can run bash scripts/dbImport.sh successfully with no issues by just entering it in the terminal and running without using npm. I can also run bash scripts/dbImport.sh <params> no problem. Where i get the issue is when running via npm run test dbSetup or npm run restore-db this then generates the prefix error message
nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/Users/scottbarrett/.nvm/versions/node/v9.8.0" Run unset npm_config_prefixto unset it. npm ERR! code ELIFECYCLE npm ERR! errno 11 npm ERR! Module@version test-dbSetup:bash scripts/dbImport.sh param1 param2 npm ERR! Exit status 11

@sbarrett08
Copy link
Author

Unfortunately i'm restricted to what i'm allowed to share so i'm trying to redact as much as possible to keep within limits

@ljharb
Copy link
Member

ljharb commented Jul 26, 2018

Instead of using bash, can the script be made executable?

@sbarrett08
Copy link
Author

I don't think the script is the issue as there are other members on the team using nvm working on this particular module with the npm commands executing successfully and don't experience the same issue i get, nor have they ever seen this type of error before 😕

@sbarrett08
Copy link
Author

When i have ran the printenv command this is the PATH result from the output: PATH=/usr/local/apache-maven-3.3.9/bin:/usr/local/apache-maven-3.3.9/bin:/usr/local/apache-maven-3.3.9/bin:/usr/local/apache-maven-3.3.9/bin:/usr/local/apache-maven-3.3.9/bin:/Users/scottbarrett/.nvm/versions/node/v9.8.0/bin:/usr/local/apache-maven-3.3.9/bin:/usr/local/apache-maven-3.3.9/bin:/usr/local/apache-maven-3.3.9/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/local/nodejs/bin:/usr/local/nodejs/bin:/usr/local/nodejs/bin:/usr/local/nodejs/bin

@ljharb
Copy link
Member

ljharb commented Jul 28, 2018

Hmm, i see the proper nvm path there shadowing your system node.

In the script environment, what do these commands output?

@sbarrett08
Copy link
Author

/Users/scottbarrett/.nvm/versions/node/v9.8.0/lib
└── npm@6.2.0

/Users/scottbarrett/.nvm/versions/node/v9.8.0

@sbarrett08
Copy link
Author

When i added those commands to the script the above was the output, same as previous

@ljharb
Copy link
Member

ljharb commented Jul 30, 2018

Is your home directory a symlink? What shell are you using?

@sbarrett08
Copy link
Author

I'm not sure, symlink it's possible, any advice how can i check that? I may have had to do something with that when i was trying to resolve earlier issues. Shell is bash, Mac OS

@sbarrett08
Copy link
Author

@ljharb Would removing an reinstalling nvm be an option to try?

@ljharb
Copy link
Member

ljharb commented Aug 4, 2018

@sbarrett08 it's certainly worth a shot.

@sbarrett08
Copy link
Author

Tried removing via the README uninstall option, reinstalled and still have the same issue :(

@sbarrett08
Copy link
Author

sbarrett08 commented Aug 6, 2018

Just ran another nvm debug, here is the output, the prefix lines are all empty

nvm --version: v0.33.11
$TERM_PROGRAM: Apple_Terminal
$SHELL: /bin/bash
$SHLVL: 1
$HOME: /Users/scottbarrett
$NVM_DIR: '$HOME/.nvm'
$PATH: /usr/local/apache-maven-3.3.9/bin:/usr/local/apache-maven-3.3.9/bin:/usr/local/apache-maven-3.3.9/bin:$NVM_DIR/versions/node/v9.8.0/bin:/usr/local/apache-maven-3.3.9/bin:/usr/local/apache-maven-3.3.9/bin:/usr/local/apache-maven-3.3.9/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
$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.5.0 Darwin Kernel Version 17.5.0: Mon Mar 5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64'
OS version: Mac 10.13.4 17E199
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.8.1
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: v9.8.0
which node: $NVM_DIR/versions/node/v9.8.0/bin/node
which iojs:
which npm: $NVM_DIR/versions/node/v9.8.0/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v9.8.0
npm root -g: $NVM_DIR/versions/node/v9.8.0/lib/node_modules

@ljharb
Copy link
Member

ljharb commented Aug 6, 2018

So, to reiterate:

  • nvm is working fine on the shell, and in npm run-scripts
  • nvm is working fine in your bash script when ran via the terminal
  • nvm is not working fine in your bash script when it is ran via npm run-script
  • nvm works fine on your coworkers' machines when running the bash script via npm run-script

Between your machine and a coworker's where it works - are there any differences in nvm debug output, printenv output, or node/npm/nvm versions?

@sbarrett08
Copy link
Author

Hi,

nvm is working fine on the shell, and in npm run-scripts

nvm is working fine on the shell and in npm run-scripts where the npm command contains only one action, where an npm run-script command contains one action plus && a reference to another npm command the issue occurs.

nvm is working fine in your bash script when ran via the terminal

Correct

nvm is not working fine in your bash script when it is ran via npm run-script

Not quite as per first point if npm run-script command has only once action, this works fine

nvm works fine on your coworkers' machines when running the bash script via npm run-script

correct

My co-workers nvm debug output is:
nvm --version: v0.33.2
$SHELL: /bin/bash
$HOME: /Users/nick
$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.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64 i386 MacBookPro11,4 Darwin'
OS version: Mac 10.13.6 17G65
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/bin/git, git version 2.14.3 (Apple Git-98)
nvm current: v6.11.1
which node: $NVM_DIR/versions/node/v6.11.1/bin/node
which iojs:
which npm: $NVM_DIR/versions/node/v6.11.1/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v6.11.1
npm root -g: $NVM_DIR/versions/node/v6.11.1/lib/node_modules

and the nvm debug is:
MANPATH=/Users/nick/.nvm/versions/node/v6.11.1/share/man:/usr/local/opt/coreutils/libexec/gnuman:
TERM_PROGRAM=Apple_Terminal
NVM_CD_FLAGS=
ANDROID_HOME=/usr/local/opt/android-sdk
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/vj/_5xnff_97t3462_ylvhpkf640000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.1a2eIJHG9S/Render
TERM_PROGRAM_VERSION=404
TERM_SESSION_ID=E2E8B31C-5160-4D13-B3D3-AEE826A5387D
NVM_DIR=/Users/nick/.nvm
USER=nick
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.Aqk4kBbpF5/Listeners
PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/Users/nick/.nvm/versions/node/v6.11.1/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin
PWD=/Users/nick
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
LANG=en_GB.UTF-8
XPC_FLAGS=0x0
PS1=[\u]$(parse_git_branch) $
XPC_SERVICE_NAME=0
HOME=/Users/nick
SHLVL=1
LOGNAME=nick
NVM_BIN=/Users/nick/.nvm/versions/node/v6.11.1/bin
DISPLAY=/private/tmp/com.apple.launchd.sCxzSCOibE/org.macosforge.xquartz:0
OLDPWD=/Users/nick/personal/catdog-db
_=/usr/local/opt/coreutils/libexec/gnubin/printenv

Some slight edits out for secure bits.

There is also a different node version in play on my colleagues machine but even why i use that version the error i get is the same.

I only raised the issue over on npm to try and work the problem from both ends just in case there could have been an overlap, many thanks for your help :)

@ljharb
Copy link
Member

ljharb commented Aug 13, 2018

aha, [ -f ~/.bash_profile ] && . ~/.bash_profile might be the problem - presumably bash_profile has lines that source nvm itself. When you first load your terminal, is there a node/npm activated, or do you have to nvm use explicitly? What if you run nvm alias default node?

@sbarrett08
Copy link
Author

My bash profile doesn't have much in it, only a few api keys, some mongoDB params exported like DB_HOST, DB_USER etc.

I have these exports for some java stuff:
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=/usr/local/apache-maven-3.3.9/bin:$PATH

The only reference to nvm in the bash_profile is what gets added to the bash profile from the readme:
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

When i've opened a new terminal window there does seem to be node already active but it is the latest version of node installed as default via nvm, not explicitly invoked. nvm alias default node returns default -> node (-> v10.8.0)

@ljharb
Copy link
Member

ljharb commented Aug 14, 2018

Sourcing nvm.sh (via sourcing bash_profile) would re-use a potentially different version of node; on this case, 10.8 instead of 9.8.

tbh I’d recommend not relying on bash_profile in the script, but instead having it source a different .sh file.

@sbarrett08
Copy link
Author

sbarrett08 commented Aug 14, 2018

It's not really an option for me to change this particular script as it's in use by all members of the team and works successfully for them. I think it's something somewhere in my mac that is causing this but aint got no clue where or what.

You mentioned before about a symlink, how could i check for this?

When i've removed nvm from my system and installed node via brew the issue obviously is no longer present and everything works as expected.

With nvm installed I've removed all versions of node but one (6.11.1) so this should prevent the suggestion of different versions of node being re-used but the error is still present. There is a .nvmrc file present in the repo for the project with 6.11.1 as the node version so hence the keeping them the same version but still getting the error.

@sbarrett08
Copy link
Author

Are there any sort of preferences files or group user permissions somewhere that could be potential to look at?

@ljharb
Copy link
Member

ljharb commented Aug 28, 2018

Not that i can think of - I’d compare home dir file structures and permissions, env vars, profile files, with a coworker for whom it works, and see what differences pop up.

@everdimension
Copy link

everdimension commented Sep 14, 2018

I'm having the same issue. It seems to be related to the fact that I recently updated nvm.

In iterm, I have this:

~ $ node --version
v10.9.0
~ $ nvm version
v10.9.0

But then I run tmux and see this message:

nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local"
Run npm config delete prefix or nvm use --delete-prefix v10.9.0 --silent to unset it.

In tmux, here's what the following commands display:

~ $ node --version
v9.7.1
~ $ nvm --version
0.33.11
~ $ nvm version
system
~ $ nvm ls default
        v10.9.0

@ljharb
Copy link
Member

ljharb commented Sep 14, 2018

@everdimension i believe this often happens in tmux if you're copying PATH variables, but changing them, as part of initializing tmux. Do you have anything in your tmux configs that might be doing this?

@everdimension
Copy link

@ljharb

Thank you for replying so quickly.

Well, my tmux config has been unchanged for some time, and as far as I can tell there's only this line that interacts with PATH somehow:

set-option -g default-command "reattach-to-user-namespace -l zsh"

I'm also using both zsh and oh-my-zsh, their configs have been untouched for some time as well.


I have found this issue: #1652

The workaround from the first post helps, I have added this line

PATH="/usr/local/bin:$(getconf PATH)"

just before the line where I source nvm:

source $HOME/.nvm/nvm.sh

But as I understand it it's just a workaround and nvm used to work fine without it.

@ljharb
Copy link
Member

ljharb commented Sep 14, 2018

I can't imagine what would have changed in nvm that could affect this :-/

@sbarrett08
Copy link
Author

Couldn't resolve, had to give up and hopefully after a device wipe and reset it should be resolved.

@rowild
Copy link

rowild commented Feb 21, 2019

My solution: Completely uninstall any node and node-related things (like nvm, node_moduls, $PATH vars...) on your computer including man files, packages, etc.
(https://stackoverflow.com/questions/11177954/how-do-i-completely-uninstall-node-js-and-reinstall-from-beginning-mac-os-x/11178106#11178106)

I then FIRST installed nvm again, and with nvm I installed various node version.
So far there is no annoying line in the Terminal, neither in the native one nor in VS Code.

@kate-hall
Copy link

What fixed this error for me, finally, after trying everything:

Uninstall npm.
Uninstall the homebrew version of nvm, reinstall via curl.

Most important:

In /usr/local/bin, delete the node alias.

Now it's finding the NVM default alias first, not whatever I installed via Xcode.

@ignacio-gc
Copy link

In my case I'm using a fresh install (no previous npm or node installation), and zsh, seems this line cause the problem: export NVM_DIR="$HOME/.nvm"
I replaced $HOME with the full path and is solved.

@ljharb
Copy link
Member

ljharb commented Jun 5, 2019

@ignaciocaamanio what is the value of $HOME on that line?

@ignacio-gc
Copy link

ignacio-gc commented Jun 5, 2019

Sorry, I don't understand, you mean with what I replaced "$HOME/.nvm" ?
I put: "/home/nacho/.nvm"

@ljharb
Copy link
Member

ljharb commented Jun 5, 2019

What I mean is, what is the exact value of the environment variable "HOME" - since i'd expect it to be equivalent to /home/nacho.

@ignacio-gc
Copy link

It is /home/nacho. I tried again with $HOME and the problem come back. Don't make sense but that is what happen.

@ljharb
Copy link
Member

ljharb commented Jun 6, 2019

That definitely doesn't make sense. Are you sure that's the value of it on the line immediately before the export NVM_DIR line?

@ignacio-gc
Copy link

I put echo $HOME before export NVM_DIR line and the output is /home/nacho, as expected.

@ljharb
Copy link
Member

ljharb commented Jun 6, 2019

i'm not sure what to do about that then - your fix shouldn't have been necessary, unless your shell itself is broken ¯\_(ツ)_/¯

@ignacio-gc
Copy link

Sorry to post another comment, @ljharb the nvm installation adds export NVM_DIR="$HOME/.nvm" to .bashrc
If I change it to export NVM_DIR="$HOME.nvm" (without slash) the nvm is not compatible with the npm config "prefix" option alert disappears. If I echo my $HOME the path ends with slash, previously I've copied the path wrong (without slash)

@ljharb
Copy link
Member

ljharb commented Jul 8, 2019

@ignaciocaamanio $HOME incorrectly has a trailing slash in it - remove that (wherever it's defined) and everything should work again.

@iamjaredwalters
Copy link

iamjaredwalters commented Aug 7, 2019

Edit: scratch that, still have the issue when using nvm install

Using the following fixed this issue for me:

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```

@aleen42
Copy link

aleen42 commented Jan 16, 2020

Is that bug fixed?

I have tried the following js:

// test.js
console.log(require('child_process').execSync('. ~/.nvm/nvm.sh && nvm list', {encoding: 'utf8'}));

It's ok when running with node directly, but if I try to run with npm, it throws the following error:

nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/root/.nvm/versions/node/v10.18.1"
Run `unset npm_config_prefix` to unset it.
child_process.js:669
    throw err;
    ^

Error: Command failed: . ~/.nvm/nvm.sh && nvm list
nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/root/.nvm/versions/node/v10.18.1"
Run `unset npm_config_prefix` to unset it.

    at checkExecSyncError (child_process.js:629:11)
    at Object.execSync (child_process.js:666:13)
    at Object.<anonymous> (/root/test/test.js:1:38)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@1.0.0 nvm: `node ./test.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@1.0.0 nvm script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /cache/.npm/_logs/2020-01-16T10_13_19_268Z-debug.log

How to solve this? And my NVM version is 0.33.11, and there is no problems when downgrading to 0.33.2

@ljharb
Copy link
Member

ljharb commented Jan 16, 2020

It should be, but nvm v0.33.11 is wildly out of date; upgrade to v0.35.2.

@aleen42
Copy link

aleen42 commented Jan 17, 2020

v0.35.2 has fixed it, thx

@infantito
Copy link

I have the same problem with vscode terminal (zsh)

`➜ nvm use
Found '/Users/.../project-name/.nvmrc' with version <10.17.0>
internal/modules/cjs/loader.js:638
throw err;
^

Error: Cannot find module '"/Users/infante/Library/Application'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at Module._preloadModules (internal/modules/cjs/loader.js:901:12)
at preloadModules (internal/bootstrap/node.js:602:7)
at startup (internal/bootstrap/node.js:273:9)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run nvm use --delete-prefix v10.17.0 to unset it.`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs followup We need some info or action from whoever filed this issue/PR.
Projects
None yet
Development

No branches or pull requests

9 participants