jorgebucaran / nvm.fish

The Node.js version manager you'll adore, crafted just for Fish
https://git.io/nvm.fish
MIT License
2.08k stars 69 forks source link

Supress insignificant package.json not found errors #145

Closed meadowsys closed 3 years ago

meadowsys commented 3 years ago

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, then pnpm i -g pnpm and pnpm 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:

image

not happening before I do the pnpm stuff:

image

jorgebucaran commented 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. 🙆‍♂️

meadowsys commented 3 years ago

cool thanks!

jorgebucaran commented 3 years ago

Could you help me understand what's happening here? Installing Node brings npm with it. Why isn't there a package.json?

ljharb commented 3 years ago

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?

jorgebucaran commented 3 years ago

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.

meadowsys commented 3 years ago

it works after I first install it, but I reinstall npm using pnpm, which probably installs it differently, causing this error

meadowsys commented 3 years ago

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

ljharb commented 3 years ago

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.

jorgebucaran commented 3 years ago

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, then pnpm i -g pnpm and pnpm i -g npm

Is that all I need to run? Am I missing any steps? @autumnblazey

meadowsys commented 3 years ago

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

meadowsys commented 3 years ago

can confirm it works, thank you!