pnpm: `pnpm add -g` fails on no global bin dir since version 7.20.0

pnpm version:

7.21.0, 7.22.0

Code to reproduce the issue:

(In isolated/docker environment) Docker image:

FROM node:16-bullseye-slim

# standard utilities we need
RUN apt-get update -qq && \
	apt-get install -y \
	    wget \
        curl \
        git \
        ca-certificates \
    --no-install-recommends && \
    rm -r /var/lib/apt/lists/*

# Install pnpm
RUN npm install -g pnpm@7

Run this code within a container using this image:

$ pnpm config set store-dir .pnpm-store
$ mkdir -p .pnpm-glob
$ mkdir -p .pnpm-bin
$ pnpm config set global-dir .pnpm-glob
$ pnpm config set global-bin-dir .pnpm-bin
$ export PATH=".pnpm-bin:$PATH"
$ pnpm --version
7.22.0
$ echo $PATH
.pnpm-bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ pnpm config list
//registry.npmjs.org/:_authToken=XXXX
global-bin-dir=.pnpm-bin
global-dir=.pnpm-glob
registry=https://registry.npmjs.org/
store-dir=.pnpm-store
user-agent=pnpm/7.22.0 npm/? node/v16.19.0 linux x64
$ pnpm add vercel -g
 ERR_PNPM_NO_GLOBAL_BIN_DIR  Unable to find the global bin directory
Run "pnpm setup" to create it automatically, or set the global-bin-dir setting, or the PNPM_HOME env variable. The global bin directory should be in the PATH.

Expected behavior:

Given that global-bin-dir option is set as per the instruction, it should not error.

Actual behavior:

Returns an error, while it worked fine with the same code before this change was introduced; https://github.com/pnpm/pnpm/issues/5841.

Additional information:

  • node -v prints:
  • 16.19.0
  • Windows, macOS, or Linux?:
  • Linux (node 16 docker image)

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 21
  • Comments: 25 (5 by maintainers)

Commits related to this issue

Most upvoted comments

This work for me in macOS Monterrey and pnpm 7.27.1

mkdir -p ~/.pnpm/store
export PNPM_HOME=~/.pnpm/store
pnpm setup
source ~/.zshrc

Run these 2 simple commands

  1. pnpm setup
  2. source ~/.zshrc

it should now work!

I’m trying to use pnpm add nx -g within a github workflow and running into this after running pnpm setup:

      - name: Install Nx 😢
        env:
          SHELL: /bin/bash
        run: |
          pnpm setup
          source /home/runner/.bashrc
          pnpm add nx -g

Nx is already an inefficient runner (and I presently don’t have a choice about using it on a project) and we’re trying to avoid running it through another node process, running it directly which requires installing it globally.

tried with 7.23.0 Still same error on macOS M1

The solution here worked for me in the context of Alpine Linux in Docker: https://github.com/pnpm/pnpm/issues/784#issuecomment-1518582235

could you just use pnpm dlx instead? If you need to install a package globally just run it once, it is better to run pnpm dlx.

@zkochan When running pnpm in a CI pipeline, what should we do to ensure  there is no “ERR_PNPM_NO_GLOBAL_BIN_DIR” error when executing the pnpm add -g *** command  in a pipeline. I use it for instance to donwload the vercel CLI in order to deploy the package I have built.

@vickvasquez the pnpm home directory is not the store. It is confusing to name it the store. The pnpm store is located at these locations: https://pnpm.io/npmrc#store-dir

Also, this issue might be fixed as we shipped some fixes to the pnpm config set command.

@kenrick95 No, older v7 versions are fine. I’ve pinned the version of pnpm in our CI/CD to pnpm@7.19 which doesn’t have this issue, only the more recent version (7.20.0 and 7.21.0 I last tested) have issues.