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
- fix(setup): update the current shell, not the preferred one ref #4658 — committed to pnpm/pnpm by zkochan 2 years ago
- fix(setup): update the current shell, not the preferred one (#4701) ref #4658 — committed to pnpm/pnpm by zkochan 2 years ago
- fix(setup): update the current shell, not the preferred one (#4701) ref #4658 — committed to pnpm/pnpm by zkochan 2 years ago
- fix: make the proxy var non-expandable ref https://github.com/pnpm/pnpm/issues/4658#issuecomment-1304421148 — committed to pnpm/components by zkochan 2 years ago
- fix(setup): pnpm_home should be a non-expandable env var ref https://github.com/pnpm/pnpm/issues/4658#issuecomment-1304421148 — committed to pnpm/pnpm by zkochan 2 years ago
fwiw running
pnpm setupdidn’t get rid of this error for me. To fix, I created a directory/Users/joeldenning/pnpmthen added the following to my zshrc:I use the brew to install
pnpm v7.0.1, and add global module occurred this error. I solved by these steps:PNPM_HOMEvariable in.zshrcpnpm setup.zshrc, findPNPM_HOMEvariable.source .zshrcHope 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:
pnpm setupPNPM_HOME=C:\Users\[your system username]\AppData\Local\pnpmto globalsystem variables, not user variables!!!%PNPM_HOME%toPathofsystem variables2022/09/22, update for macos-12.2.1 solutions:
pnpm setup, this will printPNPM_HOMEandPATHin console, such as:~/.zshrcfileHi @zkochan Maybe it needs to update the installation guide?
If you installed it with
npmyou need to update it withnpmas well. Since no global dirs were set up correctlynpm i -g pnpmonly 2 steps for me: step1:
pnpm setupstep2:source ~/.zshrc(it’s very important)then
pnpm add -g <package>that’s okUnfortunately, this has caused me a big headache with our Azure DevOps CI builds. Trying to fix using
pnpm setupdoesn’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 thepnpm setupcommand was doing and manually set the PNPM_HOME and PATH variables in the script block: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.
thats solved my problem on windows 11, thanks 😃
A boring log of what happened to me, for information only.
pnpm add -g pnpmto update to v7.0.0pnpm add -g pnpmto update to v7.0.1, encountered this issuepnpm setuppnpm add -g pnpmagain in a new terminal, issues disappears, now at v7.0.1pnpm setuppnpm add -g pnpmpnpm --version, got a new version.V6
I’m having the same issues on Windows Powershell. I tried to run
pnpm link --globaland receive:I then run
pnpm setupand see that PNPM_HOME and Path are already set. I restart Powershell and still get the above error. I even tried a manual setting ofpnpm config set store-dir C:\.pnpm-storeand that doesn’t seem to fix anything either.@zkochan Hi 👋 Confirming issue on 3 Windows PCs. Here’s how you can reproduce it (attached video of repro below):
nvs/nvm-windowsnpm i -g pnpm-gflag, example:pnpm i -g npm-check-updatesERROR Unable to find the global bin directory ... Run "pnpm setup" to create it automatically ...pnpm setup// ENVs got updated-gflag againERROR The configured global bin directory "C:\Users\User\AppData\Local\pnpm" is not in PATHnode:
v18.12.1npm:v8.19.2pnpm:v7.14.2Video 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.0doesn’t have this problem, butv7.9.1introduces 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/4744And here’s why (one of these variants):
refreshEnvVarsnot working as expected while settingPNPM_HOMEfor the first timePNPM_HOMEwas set asExpandable string(REG_EXPAND_SZ) but should be justString(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 usepnpmworked for me too.Looks like
pnpm setupcannot detect that the current shell iszsh. It check the value of$SHELLenv variable but it says bash even onzsh. I think we can check if$ZSH_VERSIONis 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:
Ok, so I follow the advice and:
Don’t know if the fact that I’m using
nvmto 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 ?
Works!
This is not related to this issue. This is about missing or incorrect peer dependencies. You need to install
@types/nodeandtypescriptglobally 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_HOMEto point to the same location asnpm bin -g, but previously this pointed to a cache that’s loaded from npm’s bin directory(?).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.
I have confirmed that 7.17.1 from a clean environment will get things properly configured. However, if you run
pnpm setupusing 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.
pnpm setuppnpm add -g pnpmpnpm --version, got a new version.npm rm -g pnpmwork for me.pnpm add -g pnpmAfter the installation is successful, the query version number is 7.1.7,npm rm -g pnpmand then query to get 7.2.1Instead 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.
USERPROFILEis not an expandable environment variable – it has a simple string value.Notice
REG_SZis the type. Compare to system with issue:You may fix your
PNPM_HOMEtype by using: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
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
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
~/.localor use npm for global packages.prefix=/home/foo/usrin their~/.npmrcfilefoocan 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 packagesIt 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 pnpmand repaired bynpm i -g pnpmI’m with debian 11 and a user
foowho handle the global dir (withprefix=/home/foo/usrin his~/.npmrc), PATH includes/home/foo/usr/binfor all users (shell is zsh for all).I tried to add
global-bin-dir=/home/foo/usr/binin ~/.npmrc,PNPM_HOME=/home/foo/.local/share/pnpmin ~/.zshenv, could helpfoobut 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/pnpmdoesn’t change anything, pnpm still use /home/foo/.local/share/pnpmSo I need to choose between
chmod g+rX o+rX /home/foo/.local/shareor not using pnpm to manage my globals packages (currently onlynpmandpnpm).I have choosen the 2nd option because
I’d like to continue using the “global” bin directory from
nvmwithpnpm, but it seems like that isn’t an option anymore.nvmautomatically 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:This is a symlink to whatever version of node nvm has active currently. However, that causes pnpm to fail with this message:
… which is sort of true, but the directory that resolves to is definitely in the PATH:
So the result is that I can’t install packages globally into different versions of node without making sure
global-bin-diris in sync before doing it (this includes pnpm itself)@zkochan we use the
aws-cdkwhich 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 usenpx aws-cdk:unfortunately
pnpx aws-cdk(orpnpm dlx aws-cdk) doesn’t work:possibly due to the mismatch that the package is called
aws-cdkbut the executable is calledcdk? 🤷♂️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.