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 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:I use the brew to install
pnpm v7.0.1
, and add global module occurred this error. I solved by these steps:PNPM_HOME
variable in.zshrc
pnpm setup
.zshrc
, findPNPM_HOME
variable.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:
pnpm setup
PNPM_HOME=C:\Users\[your system username]\AppData\Local\pnpm
to globalsystem variables
, not user variables!!!%PNPM_HOME%
toPath
ofsystem variables
2022/09/22, update for macos-12.2.1 solutions:
pnpm setup
, this will printPNPM_HOME
andPATH
in console, such as:~/.zshrc
fileHi @zkochan Maybe it needs to update the installation guide?
If you installed it with
npm
you need to update it withnpm
as well. Since no global dirs were set up correctlynpm 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 okUnfortunately, 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 thepnpm setup
command 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 pnpm
to update to v7.0.0pnpm add -g pnpm
to update to v7.0.1, encountered this issuepnpm setup
pnpm add -g pnpm
again in a new terminal, issues disappears, now at v7.0.1pnpm setup
pnpm add -g pnpm
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: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 ofpnpm config set store-dir C:\.pnpm-store
and 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-windows
npm i -g pnpm
-g
flag, example:pnpm i -g npm-check-updates
ERROR Unable to find the global bin directory ... Run "pnpm setup" to create it automatically ...
pnpm setup
// ENVs got updated-g
flag againERROR 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, butv7.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/4744And here’s why (one of these variants):
refreshEnvVars
not working as expected while settingPNPM_HOME
for the first timePNPM_HOME
was 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 usepnpm
worked for me too.Looks like
pnpm setup
cannot detect that the current shell iszsh
. It check the value of$SHELL
env variable but it says bash even onzsh
. 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:
Ok, so I follow the advice and:
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 ?
Works!
This is not related to this issue. This is about missing or incorrect peer dependencies. You need to install
@types/node
andtypescript
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 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 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.
pnpm setup
pnpm add -g pnpm
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.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.
USERPROFILE
is not an expandable environment variable – it has a simple string value.Notice
REG_SZ
is the type. Compare to system with issue:You may fix your
PNPM_HOME
type 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
~/.local
or use npm for global packages.prefix=/home/foo/usr
in their~/.npmrc
filefoo
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 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 pnpm
and repaired bynpm i -g pnpm
I’m with debian 11 and a user
foo
who handle the global dir (withprefix=/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 helpfoo
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/pnpmSo I need to choose between
chmod g+rX o+rX /home/foo/.local/share
or not using pnpm to manage my globals packages (currently onlynpm
andpnpm
).I have choosen the 2nd option because
I’d like to continue using the “global” bin directory from
nvm
withpnpm
, 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: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-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 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-cdk
but 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.