pnpm: [pnpm v7] crashes "add --global" with "ERROR  Unable to find the global bin directory"

add --global does not work without additional configuration

pnpm version: 7.0.0

Code to reproduce the issue:

npm install --global pnpm
pnpm add --global npm-run-all
ERROR  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:

pnpm add --global <module> works correctly without additional configurations

Actual behavior:

It causes an error and needs a workaround on CI

Additional information:

##[debug] Azure DevOps
##[debug] vmImage: ubuntu-20.04
##[debug]script=npm install --global pnpm
pnpm config set store-dir /home/vsts/work/1/.pnpm-store
##[debug]pnpm -v
7.0.0
##[debug]node -v
v16.14.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 66
  • Comments: 78 (20 by maintainers)

Commits related to this issue

Most upvoted comments

fwiw running pnpm setup didn’t get rid of this error for me. To fix, I created a directory /Users/joeldenning/pnpm then added the following to my zshrc:

export PATH="/Users/joeldenning/pnpm:$PATH"
export PNPM_HOME="/Users/joeldenning/pnpm"

I use the brew to install pnpm v7.0.1, and add global module occurred this error. I solved by these steps:

  1. Remove PNPM_HOME variable in .zshrc
  2. Run pnpm setup
  3. Cat .zshrc, find PNPM_HOME variable.
  4. Run source .zshrc

Hope this can help you!

“Open a new terminal to start using pnpm” is work for me.

I use windows terminal with powershell on windows10-19044, and that’s my solution:

  1. run pnpm setup
  2. add PNPM_HOME=C:\Users\[your system username]\AppData\Local\pnpm to global system variables, not user variables!!!
  3. add %PNPM_HOME% to Path of system variables
  4. restart windows terminal

image

2022/09/22, update for macos-12.2.1 solutions:

  1. run pnpm setup, this will print PNPM_HOME and PATH in console, such as:
export PNPM_HOME="/Users/xxxx/Library/pnpm"
export PATH="$PNPM_HOME:$PATH"
  1. copy these two statements and paste them to ~/.zshrc file
open ~/.zshrc
source ~/.zshrc
image
  1. restart a new terminal

Hi @zkochan Maybe it needs to update the installation guide?

If you installed it with npm you need to update it with npm as well. Since no global dirs were set up correctly npm i -g pnpm

only 2 steps for me: step1: pnpm setup step2: source ~/.zshrc (it’s very important)

then pnpm add -g <package> that’s ok

Unfortunately, this has caused me a big headache with our Azure DevOps CI builds. Trying to fix using pnpm setup doesn’t work as it only updates the bashrc file with the new settings and doesn’t update the currently running shell. I’ve tried manually reloading the bashrc file but that doesn’t seem to work inside the script. The only way I could get this to work was to dig through the code to work out what the pnpm setup command was doing and manually set the PNPM_HOME and PATH variables in the script block:

- script: |
      export PNPM_HOME="/home/vsts/.local/share/pnpm"
      export PATH="$PNPM_HOME:$PATH"
      pnpm add -g aws-cdk
    displayName: 'Install AWS CDK'

This obviously is pretty painful and will need to be done for every script that is doing a global install as part of the pipeline.

@zkochan you mentioned above that the automatic detection of the global store needed to be removed, what problems was it causing before? Is there a better workaround that I could use?

For some folks, simply opening a new terminal in vscode won’t fix the issue after running pnpm setup. You might need to fully close out of vscode and restart which fixed the issue for me (windowss 11)

This works as expected.

If you use the standalone script to install pnpm, then it will add PNPM_HOME dir to your PATH. Otherwise, you may run pnpm setup, as noted in the error message.

We had to remove “autodetection” of global bin location because it was causing more trouble than good.

I use windows terminal with powershell on windows10-19044, and that’s my solution:

  1. run pnpm setup
  2. add PNPM_HOME=C:\Users\[your system username]\AppData\Local\pnpm to global system variables, not user variables!!!
  3. add %PNPM_HOME% to Path of system variables
  4. restart windows terminal

image

2022/09/22, update for macos-12.2.1 solutions:

  1. run pnpm setup, this will print PNPM_HOME and PATH in console, such as:
export PNPM_HOME="/Users/xxxx/Library/pnpm"
export PATH="$PNPM_HOME:$PATH"
  1. copy these two statements and paste them to ~/.zshrc file
open ~/.zshrc
source ~/.zshrc
image
  1. restart a new terminal

thats solved my problem on windows 11, thanks 😃

A boring log of what happened to me, for information only.

  1. pnpm add -g pnpm to update to v7.0.0
  2. got reminded v7.0.1 became available
  3. pnpm add -g pnpm to update to v7.0.1, encountered this issue
  4. per instruction on screen: pnpm setup
  5. pnpm add -g pnpm again in a new terminal, issues disappears, now at v7.0.1
  1. Run pnpm setup
  2. Open a new terminal, run pnpm add -g pnpm
  3. Open a new terminal, run pnpm --version, got a new version.

V6

I’m having the same issues on Windows Powershell. I tried to run pnpm link --global and receive:

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

I then run pnpm setup and see that PNPM_HOME and Path are already set. I restart Powershell and still get the above error. I even tried a manual setting of pnpm config set store-dir C:\.pnpm-store and that doesn’t seem to fix anything either.

@0xlsca so the issue is when someone installs pnpm with npm and then tries to manually set PNPM_HOME on Windows? What are the steps to reproduce the issue and what would be the fix?

@zkochan Hi 👋 Confirming issue on 3 Windows PCs. Here’s how you can reproduce it (attached video of repro below):

  1. use fresh Windows (just for clarity of experiment)
  2. install Node LTS (via official .msi, or by using: nvs / nvm-windows
  3. npm i -g pnpm
  4. install any package with -g flag, example: pnpm i -g npm-check-updates
  5. ERROR  Unable to find the global bin directory ... Run "pnpm setup" to create it automatically ...
  6. pnpm setup // ENVs got updated
  7. restart terminal
  8. try to install any package with -g flag again
  9. boom, error:  ERROR  The configured global bin directory "C:\Users\User\AppData\Local\pnpm" is not in PATH

node: v18.12.1 npm: v8.19.2 pnpm: v7.14.2

Video demonstration (skip to 0:50):

https://user-images.githubusercontent.com/5501615/200105729-eac9408d-fc08-427c-824e-7df1935b2e9f.mp4

Hope it will help you 😃

UPD: pnpm v7.9.0 doesn’t have this problem, but v7.9.1 introduces it probably by: https://github.com/pnpm/pnpm/commit/8cb47ac9d2a56c9210fbdf48ace61df238131595 https://github.com/pnpm/components/commit/4b4da10e48343c4825a239c837a4255c24f41b0c Probably related to: https://github.com/pnpm/pnpm/issues/4744

And here’s why (one of these variants):

  1. Performed update in ENVs via Windows registry not recognized immediately and refreshEnvVars not working as expected while setting PNPM_HOME for the first time
  2. PNPM_HOME was set as Expandable string (REG_EXPAND_SZ) but should be just String (REG_SZ)
Video demo of fix (changing type of env right after `pnpm setup`):

https://user-images.githubusercontent.com/5501615/200107059-735fb435-9fd4-4669-88d6-76a0069af0c1.mp4

I am getting the same error when running pnpm list -g. And the trick of opening a new terminal/tab to use pnpm worked for me too.

fwiw running pnpm setup didn’t get rid of this error for me. To fix, I created a directory /Users/joeldenning/pnpm then added the following to my zshrc:

Looks like pnpm setup cannot detect that the current shell is zsh. It check the value of $SHELL env variable but it says bash even on zsh. I think we can check if $ZSH_VERSION is set instead.

I’m also stuck with this. I haven’t messed up with any env vars or so - just installed pnpm using npm some months ago. No manual changes of anything. It’s been working great! But today I’ve got the following message while installing a dependency to a new package:

image

Ok, so I follow the advice and:

image

Don’t know if the fact that I’m using nvm to switch between different versions of node could possibly be triggering changes in the global npm environment and affect pnpm?

What’s the easiest workarond for this? Setting the PNPM_HOME dir to what? How do I find that out? Or should I rather just reinstall pnpm using the standalone script instead of using npm ?

# 1.
pnpm setup

# 2.
source .zshrc

Works!

I suddenly have issues with ts-node(npm works fine):

This is not related to this issue. This is about missing or incorrect peer dependencies. You need to install @types/node and typescript globally because they are needed by ts-node.

Hello I also began seeing this issue with pnpm v7. Using this with fnm we can manually set PNPM_HOME to point to the same location as npm bin -g, but previously this pointed to a cache that’s loaded from npm’s bin directory(?).

josef ~
> fnm use 16
Using Node v16.14.2

josef ~
> npm bin -g
/Users/josef/.fnm/node-versions/v16.14.2/installation/bin
(not in PATH env variable)

josef ~
> pnpm -v
6.32.11

josef ~
> pnpm bin -g
/Users/josef/Library/Caches/fnm_multishells/96870_1651591328965/bin

josef ~
> pnpm add -g pnpm
Nothing to stop. No server is running for the store at /Users/josef/.pnpm-store/v3
Packages: +1 -1
+-
Progress: resolved 27, reused 26, downloaded 1, added 1, done

/Users/josef/.fnm/node-versions/v16.14.2/installation/pnpm-global/5:
- pnpm 6.32.11
+ pnpm 7.0.0

josef ~
> pnpm bin -g
 ERROR  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.

This thread has too many unrelated issues. I am going to close it. If there are unsolved issues, create dedicated new issues.

Initially this issue was opened for CI envs. As a rule, it is not recommended to install packages globally in CI at all.

PNPM_HOME was set as Expandable string (REG_EXPAND_SZ) but should be just String (REG_SZ)

This is done in v7.17.1 Let me know if it helped.

Also, there is a related issue here: #5696

I have confirmed that 7.17.1 from a clean environment will get things properly configured. However, if you run pnpm setup using 7.17.1+ one a Windows system that already has PNPM_HOME established, it will remain broken.

This solving problems with update. Important, do not skip opening a new terminal.

  1. Run pnpm setup
  2. Open a new terminal, run pnpm add -g pnpm
  3. Open a new terminal, run pnpm --version, got a new version.

npm rm -g pnpm work for me. pnpm add -g pnpm After the installation is successful, the query version number is 7.1.7, npm rm -g pnpm and then query to get 7.2.1

Instead of “or set the global-bin-dir setting”, the error message should instruct the reader exactly how to “set the global-bin-dir setting”. It should include the exact CLI command, perhaps with an angle-bracketed placeholder like <your path here> in place of the actual path. This would save lots of users lots of documentation combing.

It is indeed not as a simple as alphabetical ordering, but the type of the value matters. USERPROFILE is not an expandable environment variable – it has a simple string value.

C:\Users\Jason>reg query "HKCU\Volatile Environment" /v UserProfile

HKEY_CURRENT_USER\Volatile Environment
    UserProfile    REG_SZ    C:\Users\Jason

Notice REG_SZ is the type. Compare to system with issue:

C:\Users\Jason>reg query "HKCU\Environment" /v PNPM_HOME

HKEY_CURRENT_USER\Environment
    PNPM_HOME    REG_EXPAND_SZ    C:\Users\Jason\AppData\Local\pnpm

You may fix your PNPM_HOME type by using:

reg add HKCU\Environment /v PNPM_HOME /t REG_SZ /d "%PNPM_HOME%" /f

which will keep its current value but overwrite the type.

I think this issue should be Closed now. It is fixed with 7.17.1’s change. Rerunning setup won’t fix things. So maybe it could be changed to patch the type.

dont know if its related or not. (Windows 10) when i tried to add a package with -g flag “pnpm add -g” I got this error : ERROR  The configured global bin directory “C:\Users.…\AppData\Local\pnpm” is not in PATH running terminal with Run as admin solved the problem

PNPM_HOME was set as Expandable string (REG_EXPAND_SZ) but should be just String (REG_SZ)

This is done in v7.17.1 Let me know if it helped.

Also, there is a related issue here: https://github.com/pnpm/pnpm/issues/5696

not sure if it helps for everyone

pnpm config set store-dir $PNPM_HOME

As @aparajita says, this doesn’t work in a multiuser environment (with one of the users handling the global store, others using it), because default rights on the global store make it private. So you have to choose between changing default rights of the OS on ~/.local or use npm for global packages.

  • All users have prefix=/home/foo/usr in their ~/.npmrc file
  • foo can write in /home/foo/usr, especially /home/foo/usr/bin (in the $PATH of everybody) and /home/foo/usr/lib/node_module, so only him can manage global packages
  • others users can read /home/foo/usr, so they can use these global packages.

It works with npm but I didn’t find out how doing this with pnpm without changing default security rules on /home/foo/.local (where pnpm put it stuff, local packages and global ones, that’s my pb).

It’s not so important, managing my 2~3 global packages with npm is not really a pb for me, I was asking just in case I didn’t saw the good solution…

In my case pnpm was always broken by pnpm add -g pnpm and repaired by npm i -g pnpm

I’m with debian 11 and a user foo who handle the global dir (with prefix=/home/foo/usr in his ~/.npmrc), PATH includes /home/foo/usr/bin for all users (shell is zsh for all).

I tried to add global-bin-dir=/home/foo/usr/bin in ~/.npmrc, PNPM_HOME=/home/foo/.local/share/pnpm in ~/.zshenv, could help foo but or others users can’t access to this folder, so pnpm is always broken for foo or others users or both.

Specifying a custom folder PNPM_HOME=/home/foo/pnpm doesn’t change anything, pnpm still use /home/foo/.local/share/pnpm

So I need to choose between chmod g+rX o+rX /home/foo/.local/share or not using pnpm to manage my globals packages (currently only npm and pnpm).

I have choosen the 2nd option because

  • I prefer to let default rights (for security but almost because a system script may reset these rights to the default ones)
  • I’m not very confident in having two pnpm, one in /home/foo/usr/lib/node_modules/pnpm installed by npm and other in /home/foo/.local/share/pnpm/global/5/node_modules/pnpm both used by /home/foo/usr/bin/pnpm, depending if last update of pnpm was done by npm or pnpm.

I’d like to continue using the “global” bin directory from nvm with pnpm, but it seems like that isn’t an option anymore.

nvm automatically updates the shell path depending on which version of node you’re using, which means in order to make pnpm write files there I think I need to set this in my nvmrc:

global-bin-dir=/Users/me/.nvm/current/bin

This is a symlink to whatever version of node nvm has active currently. However, that causes pnpm to fail with this message:

 ERROR  The configured global bin directory "/Users/me/.nvm/current/bin" is not in PATH

… which is sort of true, but the directory that resolves to is definitely in the PATH:

$ echo $PATH
...:/Users/me/.nvm/versions/node/v16.14.0/bin:....

$ ls -l ~/.nvm/current
... /Users/me/.nvm/current -> /Users/me/.nvm/versions/node/v16.14.0

So the result is that I can’t install packages globally into different versions of node without making sure global-bin-dir is in sync before doing it (this includes pnpm itself)

@zkochan we use the aws-cdk which just installs a cmd line tool. Locally this works fine without any global install, it picks it up from the node_modules/.bin folder, but on the CI server for some reason, this doesn’t work. The only other way to get it to work is to use npx aws-cdk:

image

unfortunately pnpx aws-cdk (or pnpm dlx aws-cdk) doesn’t work:

image

possibly due to the mismatch that the package is called aws-cdk but the executable is called cdk? 🤷‍♂️

Ideally, we would like to use the same package manager for all tasks to save confusion and hence why we have historically done a global install of the package. It also obviously saves having to prefix every subsequent cdk command as we run several as part of the pipeline.