Closed meadowsys closed 3 years ago
We use npm's package.json
to figure out the current npm version after activating Node. That's just to show you the version after nvm use
.
Yeah, we can probably suppress errors here. 🙆‍♂️
cool thanks!
Could you help me understand what's happening here? Installing Node brings npm with it. Why isn't there a package.json
?
Why would there be one inside the bin folder? That’s not where npm is located; that’s where npm’s binary is symlinked into.
why not just run npm --version
?
We use realpath (command --search npm)
to find where npm is located in your system. From there, we derive the root directory, e.g., $nvm_path/v6.17.1/lib/node_modules/npm/, where there should be a package.json
.
I want to understand why that fails for this user.
it works after I first install it, but I reinstall npm using pnpm, which probably installs it differently, causing this error
maybe it could be better to use realpath (command --search npm)
first to get the executable, then run -v on that command (something like /home/kirin/.local/share/nvm/v15.11.0/bin/npm -v
) and use that
It's simply not a valid assumption that you can, in the general case, derive the npm package.json location based on the location of the npm
binary, despite it being derivable in the common case.
I'll try to reproduce this scenario in my environment, but I want to clarify a few things:
Then, on every shell startup and every time ...
I thought the error only happens when you use nvm use
to activate Node, not on every shell startup. Have you set nvm_default_version
by some chance?
npm i -g pnpm
, thenpnpm i -g pnpm
andpnpm i -g npm
Is that all I need to run? Am I missing any steps? @autumnblazey
oops, sorry didn't clarify haha
I did set nvm_default_version
, then it happens on both startup and nvm use
. also, that's all that you need to run
can confirm it works, thank you!
I know this is a bit obscure, but after installing and using a node version, the first things I do is
npm i -g pnpm
, thenpnpm i -g pnpm
andpnpm i -g npm
. Basically, I install pnpm, then reinstall pnpm and npm using pnpm, so that they are all controlled by pnpm. Then, on every shell startup and every time i switch to that node version, node complains about not finding a package.json.Can this be supressed? It doesn't affect the function of node and all globally installed packages.
the error:
not happening before I do the pnpm stuff: