nvm: nvm bug Argument list too long

Operating system and version:

nvm debug output:

Worth noting I also replicated this issue with the latest nvm release v0.38.0

$ nvm debug
nvm --version: v0.33.8
$SHELL: /bin/bash
$HOME: /home/jenkins
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: 'https://REDACTED'
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)'
uname -a: 'Linux 5.10.47-linuxkit #1 SMP Sat Jul 3 21:51:47 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux'
OS version:
curl: /usr/bin/curl, curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.53.1 zlib/1.2.7 libidn/1.28 libssh2/1.8.0
wget: /usr/bin/wget, GNU Wget 1.14 built on linux-gnu.
git: /usr/bin/git, git version 2.24.4
grep: alias grep='grep --color=auto'
	/usr/bin/grep (grep --color=auto), grep (GNU grep) 2.20
awk: /usr/bin/awk, GNU Awk 4.0.2
sed: /usr/bin/sed, sed (GNU sed) 4.2.2
cut: /usr/bin/cut, cut (GNU coreutils) 8.22
basename: /usr/bin/basename, basename (GNU coreutils) 8.22
rm: /usr/bin/rm, rm (GNU coreutils) 8.22
mkdir: /usr/bin/mkdir, mkdir (GNU coreutils) 8.22
xargs: /usr/bin/xargs, xargs (GNU findutils) 4.5.11
nvm current: none
which node: which: no node in (/opt/android-sdk/emulator:/opt/android-sdk/platform-tools:/opt/android-sdk/tools/bin:/opt/android-sdk/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/codeql:/opt/apache-maven-3.5.4/bin:$HOME/.local/bin:$HOME/bin)
which iojs: which: no iojs in (/opt/android-sdk/emulator:/opt/android-sdk/platform-tools:/opt/android-sdk/tools/bin:/opt/android-sdk/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/codeql:/opt/apache-maven-3.5.4/bin:$HOME/.local/bin:$HOME/bin)
which npm: which: no npm in (/opt/android-sdk/emulator:/opt/android-sdk/platform-tools:/opt/android-sdk/tools/bin:/opt/android-sdk/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/codeql:/opt/apache-maven-3.5.4/bin:$HOME/.local/bin:$HOME/bin)
npm config get prefix: bash: npm: command not found
npm root -g: bash: npm: command not found

nvm ls output:

$ nvm ls
            N/A
node -> stable (-> N/A) (default)
iojs -> N/A (default)

How did you install nvm?

The curl | bash method…

What steps did you perform?

As of today’s NodeJS release NVM breaks when using set -a bash shell option. This is only an issue in bash as far as I know and only when set -a option is used.

Example (MUST be from a bash shell):

set -a
source .nvm/nvm.sh
nvm install 12

What happened?

Here’s the exact commands and error output:

$ set -a

$ source .nvm/nvm.sh

$ nvm install 12
bash: /usr/bin/mkdir: Argument list too long
bash: /usr/bin/awk: Argument list too long
bash: /usr/bin/awk: Argument list too long
bash: /usr/bin/grep: Argument list too long
bash: /usr/bin/sort: Argument list too long
Version '12' not found - try `nvm ls-remote` to browse available versions.

$ echo $?
3

What did you expect to happen?

It should have installed the latest NodeJS v12. If you disable auto-export in bash via set +a it works again.

Workaround

Run set +a if you’re using the auto-export bash option before installing via nvm. set +a will disable the bash option and NVM will then succeed.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 51 (22 by maintainers)

Commits related to this issue

Most upvoted comments

I was able to reproduce it with that version of sh; I should have a fix merged soon.

@edalex-ian my understanding is that set -a makes nvm vulnerable to certain piped input being considered “too long”, and since some of that input is “the list of published node versions”, it was just a matter of time before node released enough versions to trigger this time bomb.

The best fix would be to convince AWS CodeBuild to stop setting -a, but obviously if nvm can fix it that’s fine too.

This should be fixed in #2581, altho yet unreleased. Closing.

This issue doesn’t seem to be resolved, pulled the latest master and I’m still getting the error as above:

export NVM_DIR="$HOME/.nvm"
git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
cd "$NVM_DIR"
. $NVM_DIR/nvm.sh
cd $CODEBUILD_SRC_DIR
nvm install 16.8.0
nvm alias default 16.8.0
Cloning into '/root/.nvm'...
/root/.nvm/nvm.sh: line 1398: /usr/bin/mkdir: Argument list too long
/root/.nvm/nvm.sh: line 1399: /usr/bin/awk: Argument list too long
/root/.nvm/nvm.sh: line 1441: /usr/bin/awk: Argument list too long
/root/.nvm/nvm.sh: line 45: /usr/bin/grep: Argument list too long
/root/.nvm/nvm.sh: line 1455: /usr/bin/sort: Argument list too long
Version '16.8.0' not found - try `nvm ls-remote` to browse available versions.

I can also confirm that set +a before executing mvn seems a good workaround for the issue in AWS CodeBuild.

However, to better diagnose it, I have line numbers in my output, which are missing from initial report:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source "$HOME/.nvm/nvm.sh"
nvm install v15.14.0

/root/.nvm/nvm.sh: line 1378: /usr/bin/mkdir: Argument list too long
/root/.nvm/nvm.sh: line 1380: /usr/bin/awk: Argument list too long
/root/.nvm/nvm.sh: line 1420: /usr/bin/awk: Argument list too long
/root/.nvm/nvm.sh: line 44: /usr/bin/grep: Argument list too long
/root/.nvm/nvm.sh: line 1434: /usr/bin/sort: Argument list too long

@ljharb ok, I think I figured out my problem. Your fix appears to work.

FROM centos:7
RUN set -ex; \
  yum makecache fast; \
  yum install -y git coreutils curl;\
  yum clean all
RUN adduser test

USER test
WORKDIR /home/test
RUN set -ex; \
  curl -o- https://raw.githubusercontent.com/ljharb/nvm/ff3b1b8634ebf7c5a6a0c51e6e753cb854c4da73/install.sh | bash; \
  cd .nvm; \
  git fetch https://github.com/ljharb/nvm ff3b1b8634ebf7c5a6a0c51e6e753cb854c4da73; \
  git checkout FETCH_HEAD
ENTRYPOINT ["/bin/bash", "-la"]
docker build -t nvm .
docker run -it --rm nvm
nvm install 12

Works! 😄

I can confirm I’m seeing a similar issue dealing with AWS CodeBuild. A single line change was pushed that doesn’t build today but built fine yesterday. I also use to just get -bash: $(nvm_sanitize_path “${NPM_CONFIG_PREFIX}”);: command not found but today instead I get the “Argument List too long” series of errors. I’ve not manually set set -a so it must be how CodeBuild works I would guess?

Bare in mind, in the comments some people say set +a and other set -a. @GamesmenJordan your temp fix does not work for me unfortunately. Could you share your first steps of yml?

There is nothing of any particular interest, I install a couple of standard packages and store a few environment variables related to our application itself and that’s all. Nothing that would change the default configuration of CodeBuild or nvm.

I also noted you put set -a whereas I put set +a. My understanding is that CodeBuild itself already runs with set -a by default, so declaring set -a in your build script does nothing unless you have otherwise declared set +a earlier in the script and want to switch back.

@ljharb per my original description and docker container: this bug does not affect zsh. This is specifically a bash bug. set +x is a bash shell option to workaround. If you’re writing a test I recommend calling the test with /bin/bash regardless of the shell for the calling user.

Yeah, it’s always amazingly hard to find low level specifics in CodeBuild doco. But this point makes it rather explicit that it uses sh:

https://docs.aws.amazon.com/codebuild/latest/userguide/troubleshooting.html#troubleshooting-sh-build-images

However there is also an env setting I think you can use to request bash - however our build which had the issue definitely does not try and use that, so I’m pretty sure we’re on sh.

By my recollection, CodeBuild uses sh by default and optionally bash.

We are facing a similar issue on AWS codepipeline/codebuild. Is there a likely date for when this issue will be fixed? We are not sure if we want to use the workaround in case it causes any other issues.

Updated original description. Instead of “as of today’s NVM release” I really meant “NodeJS release.”

Let me know if you’re able to reproduce it using the Docker image.

I can check. I’ll also try to reproduce with a public docker container to help with testing.

I’ll check and report back.

@sgleske-ias it’s highly likely that your internal mirror’s content is longer than that produced by nodejs.org/dist/index.tab, and as such, you may be hitting this error before every other nvm user.