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

pnpm add -g fails on no global bin dir since version 7.20.0 #5883

Open
FreekVR opened this issue Jan 5, 2023 · 25 comments
Open

pnpm add -g fails on no global bin dir since version 7.20.0 #5883

FreekVR opened this issue Jan 5, 2023 · 25 comments

Comments

@FreekVR
Copy link

FreekVR commented Jan 5, 2023

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; #5841.

Additional information:

  • node -v prints:
  • 16.19.0
  • Windows, macOS, or Linux?:
  • Linux (node 16 docker image)
@FreekVR
Copy link
Author

FreekVR commented Jan 5, 2023

It seems this is actually occuring after 7.20.0, not 7.21.0, so may be related to this change;
https://github.com/pnpm/pnpm/pull/5829/files

7.19.0 works

@coodyme
Copy link

coodyme commented Jan 5, 2023

@FreekVR I tried 7.19.0 and i get the same error

@vaidotaslipskas
Copy link

tried with 7.23.0 Still same error on macOS M1

@jasongornall-dd
Copy link

bumping this

@gabygandrade
Copy link

+1 seeing the same issue with 7.26.0 on MacOS M1

@hxtree
Copy link

hxtree commented Feb 6, 2023

+same ubuntu dev container

@PlanCZero
Copy link

same issue with 7.26.0 on MacOS M2

@sethgw
Copy link

sethgw commented Feb 10, 2023

same

1 similar comment
@leonardo-ornelas
Copy link

same

@maxkobzev
Copy link

actually can't update pnpm itself - pnpm add -g pnpm - the same error

@vickvasquez
Copy link

vickvasquez commented Feb 24, 2023

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

dannysmith added a commit to dannysmith/dotfiles that referenced this issue Feb 25, 2023
@kenrick95 kenrick95 changed the title pnpm add -g fails on no global bin dir since version 7.21.0 pnpm add -g fails on no global bin dir since version 7.19.0 Feb 28, 2023
@kenrick95
Copy link
Member

Probably related to #4658

@FreekVR did your issue occur only on these recent pnpm version or it happen to all pnpm 7 versions?

@FreekVR
Copy link
Author

FreekVR commented Feb 28, 2023

@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.

@kenrick95 kenrick95 changed the title pnpm add -g fails on no global bin dir since version 7.19.0 pnpm add -g fails on no global bin dir since version 7.20.0 Feb 28, 2023
@elmeerr
Copy link

elmeerr commented Mar 11, 2023

actually can't update pnpm itself - pnpm add -g pnpm - the same error

@maxkobzev I was facing the same issue when trying to update from 7.16 to 7.29 and the issue was because I had node servers running...maybe that can help you.

@zkochan
Copy link
Member

zkochan commented Mar 12, 2023

@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.

@TechWatching
Copy link

@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.

@zkochan
Copy link
Member

zkochan commented Mar 12, 2023

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.

@TechWatching
Copy link

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.

Yes it does the job for my use case thanks 👍. Yet I can see some use cases where I would need to execute several commands from a CLI and pnpm dlx would not be the most appropriate.

@zkochan
Copy link
Member

zkochan commented Mar 12, 2023

Yeah, pnpm dlx is currently reinstalling the package every time. We should make it so that repeat execution reuses the installation from the previous run (in some timeframe).

@shellscape
Copy link
Contributor

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.

@chokri
Copy link

chokri commented Jun 30, 2023

I just added pnpm setup --force and it worked for me.

@stephenhmarsh
Copy link

The solution here worked for me in the context of Alpine Linux in Docker: #784 (comment)

@lesar
Copy link

lesar commented Nov 15, 2023

I'am on Fedora 38
I have installed npm by nvm

$ node -v
v20.9.0
$ npm -v
10.1.0
$ pnpm -v
8.10.5

if I make:
$ pnpm setup

then

$ pnpn add -g pnpm
Nothing to stop. No server is running for the store at /home/leonardo/.local/share/pnpm/store/v3
Already up to date
Progress: resolved 1, reused 0, downloaded 0, added 0, done
Done in 2.5s

work fine (no error)

I have try to follow nvm pnpm executable on
/home/leonardo/.nvm/versions/node/v20.9.0/lib/node_modules/corepack/shims/pnpm

but after a while my eyes crossed.
typing this:

$ /home/leonardo/.nvm/versions/node/v20.9.0/lib/node_modules/corepack/shims/pnpm -v
8.10.5
$ ~/.local/share/pnpm/pnpm -v
8.10.5

show the same version ...
but I didn't understand much about it.
I'm not sure they are the same executable but at the last have the same version

My question is:
Anyone know if in my use case
(npm by nvm and pnpm by npm)
if there will be any future hidden problems to solve
pnpm add -g pnpm
by doing
pnpm setup
like I have doing!?

best regards,
Leonardo

@kale1d0code
Copy link

kale1d0code commented Jan 25, 2024

I've been having this problem when trying to install global packages during postStartCommand in a devcontainer.

no matter what I do, sourcing the .bashrc file makes no difference.
it works fine after the container has started, although I kind of needed my global packages installed before that point.

I've tried writing this out directly in the script as well as in its own file howver it doesn't work

ERR_PNPM_NO_GLOBAL_BIN_DIR  Unable to find the global bin directory

SHELL=bash pnpm setup
source ~/.bashrc
pnpm add -g nodemon

pnpm version 8.14.3

@ZowWeb
Copy link

ZowWeb commented Apr 14, 2024

Run these 2 simple commands

  1. pnpm setup
  2. source ~/.zshrc

it should now work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests