Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm seems to be tripping on asdf #162

Closed
Jwashton opened this issue Feb 15, 2017 · 35 comments
Closed

npm seems to be tripping on asdf #162

Jwashton opened this issue Feb 15, 2017 · 35 comments

Comments

@Jwashton
Copy link
Contributor

Jwashton commented Feb 15, 2017

Any invocation of npm on my system seems to be throwing this warning:

npm WARN lifecycle The node binary used for scripts is /home/jwashton/.asdf/shims/node but npm is using /home/jwashton/.asdf/installs/nodejs/7.5.0/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.

A quick Google search brought me to this issue for npm. The most helpful bit being the last comment in the thread where @addaleax elaborated on the --scripts-prepend-node-path option.

My current best guess is that on this line process.execPath returns the bin path, and not the shim path. It then compares the that to the shim path in $PATH and raises alarms.

This doesn't seem to be causing issues, because npm is adding the bin we want it to use anyways, but I still don't like the warning. If the root cause is fixable (on either side) then I would be a happy man. Failing that, can we at least acknowledge the --scripts-prepend-node-path flag here? Either setting it automatically in asdf-node or leaving a message about it in the docs?

P.S. I apologize if this issue should have been submitted on asdf-node, but I wasn't sure what implications this might have for the way asdf shims things in general.

@Stratus3D
Copy link
Member

I don't think we will be able to fix this on the asdf side (at least not without changing how shims work). The shim will always be on your $PATH and the actual binary will not be (unless something else has added it). I'm not familiar with Node.JS, but maybe --scripts-prepend-node-path is all we need. @asdf-vm/maintainers any thoughts on this?

@vic
Copy link
Contributor

vic commented Jun 14, 2017

Yep, I noticed something similar when using asdf-ocaml, the way it works in the ocaml plugin is, it has an exec-env script that basically just sets the environment for the ocaml installation (env variables are exported by opam itself) and part of that env setup made by opam is it actually prepends the real binaries path into PATH so they come before the shims as you'd have in your interactive shell.

So I guess it would be fine for this to be handled on a per-plugin basis, and asdf-node should setup the correct env for running its shims.

@SidOfc
Copy link

SidOfc commented Aug 11, 2017

While it is a somewhat older issue, using asdf reshim nodejs <your-installed-version> fixed this for me on macOS 10.12.6 (Sierra). If it doesn't, try this afterwards: source ~/.zshrc or source ~/.bashrc.

@setsun
Copy link

setsun commented Nov 8, 2017

Is there a way to fix this without asdf reshim nodejs? Every time I install a global package it seems like I need to reshim to have it recognized in my PATH

@SidOfc
Copy link

SidOfc commented Jan 18, 2018

Unfortunately, I haven't found anything that would result in a permanent fix. This is probably the reason that the reshim command exists in the first place, so you can fix the oddball errors when they occur (slightly more annoying when it happens often).

Maybe, in the case of NPM there are additional path issues since you can have "local" packages and "global" packages that have the same name I guess. I'm not sure, it's probably really tricky to fix though.

In some cases I end up reshimming or removing some of the lang-plugins because I think the issue lies within. Then later, I find out that it was because (I'm on a mac btw) Homebrew node was used instead of ASDF node. So be sure to check that too if you happen to use Homebrew :)

@joemsak
Copy link

joemsak commented Apr 17, 2018

@SidOfc your advice to reshim and re-source zsh isn't working for me :(

work % npm i -g npm
⸨       ░░░░░░░░░░░⸩ ⠹ extract:npm: verb lock using /Users/joemsak/.npm/_locks/staging-513131f1064c0873.lock for /Users/joemsak/.asd
/Users/joemsak/.asdf/installs/nodejs/9.11.1/.npm/bin/npx -> /Users/joemsak/.asdf/installs/nodejs/9.11.1/.npm/lib/node_modules/npm/bin/npx-cli.js
/Users/joemsak/.asdf/installs/nodejs/9.11.1/.npm/bin/npm -> /Users/joemsak/.asdf/installs/nodejs/9.11.1/.npm/lib/node_modules/npm/bin/npm-cli.js
+ npm@5.8.0
added 523 packages in 8.926s
work % npm -v
5.6.0
work % asdf reshim nodejs
work % npm -v
5.6.0
work % . ~/.zshrc
work % npm -v
5.6.0
# .zshrc
. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash

@SidOfc
Copy link

SidOfc commented Apr 17, 2018

Hmmn that is unfortunate @joemsak, I usually do a reshim without version but when in doubt, I try it with the version included: asdf reshim nodejs 9.11.1. It could also be that the nodejs you're running might not be managed by asdf. This can be checked by running which node and which npm, it should be something like this:

image

Also, which version of asdf are you running? If a version-specific reshim doesn't work, perhaps it might help to update your plugins and/or asdf itself. I remember running into some issues using an older version of the asdf nodejs plugin.

  • plugins: asdf plugin-update --all
  • asdf: asdf update

As a last resort I would try reinstalling said Node version, I did this a few times for Node myself so you're not alone in these issues :)

  • To remove old node: asdf plugin-remove nodejs.
  • Ensure that the ~/.asdf/installs/nodejs folder is also removed, if it isn't, run rm -rf ~/.asdf/installs/nodejs/9.11.1.
  • Reinstall node: asdf install node 9.11.1 asdf plugin-add nodejs.
  • Reinstall specific Node version asdf install nodejs 9.11.1
  • Restart everything, kill zsh, any tmux/screen sessions, your terminal and see if it works.

Let me know what happens, good luck 👍

@joemsak
Copy link

joemsak commented Apr 17, 2018

So I followed your instructions before the uninstall stuff

screen shot 2018-04-17 at 1 54 58 pm

And now when trying to uninstall / reinstall, I can't :(
screen shot 2018-04-17 at 1 58 49 pm

@joemsak
Copy link

joemsak commented Apr 17, 2018

Just rebooted ... no difference :(

@joemsak
Copy link

joemsak commented Apr 17, 2018

I haven't done anything else between then and this screenshot .... this is getting weird

screen shot 2018-04-17 at 2 58 19 pm

@SidOfc
Copy link

SidOfc commented Apr 17, 2018

@joemsak Woops! My bad, just did a quick asdf -h to figure out why your command does not work.
If you've uninstalled the plugin you need to reinstall it first by issueing: asdf plugin-add nodejs.

Then retry the asdf install nodejs 9.11.1 command again.

@joemsak
Copy link

joemsak commented Apr 17, 2018

Ooh boy I should have figured that out on my own, sorry ... will report back asap

@joemsak
Copy link

joemsak commented Apr 17, 2018

Still the same issue .... npm does not update to 5.8.0, stays stuck at 5.6.0 ... everything else is also still the same

@SidOfc
Copy link

SidOfc commented Apr 21, 2018

@joemsak apologies for the late reply.
I decided to try it myself just now and it isn't working for me either, upgrading npm doesn't seem to do anything. I've also taken all steps I provided above to ensure it does not lie within the installation.

In my specific case it is about node version 8.4.0 instead of 9.11.1, this seems to be something within asdf or asdf-nodejs. I'm going to figure out if I can make it work and will report back later.

@SidOfc
Copy link

SidOfc commented Apr 21, 2018

I see some time ago you had the same issue with node 9.9.0 here on asdf-vm/asdf-nodejs#56.
The command for me mentioned by @dipnlik correctly installed latest version of npm for me:

cd ~/.asdf/installs/nodejs/[VERSION]/lib && npm i npm

note: Do not forget to change "[VERSION]" with the actual nodejs version.

Could you try and see if maybe this does work for 9.11.1? One can hope ;)

@joemsak
Copy link

joemsak commented Apr 25, 2018

Sorry, no dice :(

screen shot 2018-04-25 at 12 57 28 pm

@SidOfc
Copy link

SidOfc commented Apr 26, 2018

From your screenshot I see you ran npm i -g npm, could you try using exactly: npm i npm (as provided in the example, e.g. without the -g switch) and report back? Just combing through the possibilities.

@evolve2k
Copy link

evolve2k commented Jul 2, 2018

After earlier having applied 'npm config set scripts-prepend-node-path true' which I think was the command that broke webpack running for me.

ref: https://stackoverflow.com/questions/51128568/webpack-production-build-generating-no-build-output-and-almost-no-terminal-log-m

I fixed my issue by running:

$ asdf plugin-update --all
$ asdf update
$ npm i npm

-- thx to @SidOfc

@corysimmons
Copy link

@Stratus3D pinging you to respond to @vic #162 (comment)

So I guess it would be fine for this to be handled on a per-plugin basis, and asdf-node should setup the correct env for running its shims.

The warning is pretty annoying when launching even just a few processes.

image

@joemsak
Copy link

joemsak commented Aug 22, 2018

sorry @SidOfc, just did @evolve2k's advice in zsh / iterm2 in a new window:

~ % npm i npm
npm WARN saveError ENOENT: no such file or directory, open '/Users/joemsak/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/joemsak/package.json'
npm WARN joemsak No description
npm WARN joemsak No repository field.
npm WARN joemsak No README data
npm WARN joemsak No license field.

+ npm@6.4.0
updated 1 package and audited 5003 packages in 6.913s
found 0 vulnerabilities

~ % npm -v
6.2.0
~ % node -v
v10.7.0
~ % asdf reshim nodejs
~ % npm -v
6.2.0

@SidOfc
Copy link

SidOfc commented Aug 22, 2018

@joemsak well, this time you are not in the correct location.
You know that you need to cd into your node install, then run the exact command right? Follow my instructions exactly:

cd ~/.asdf/installs/nodejs/[VERSION]/lib && npm i npm

Once again, replace [VERSION] with the proper version number and skip the -g switch on npm i npm. At the moment you are in ~ which is just your home directory.

Note that I am not sure if this actually works, I've done it on macOS 10.12 (Sierra) and it did work for me so I am kinda assuming it works when executed properly. Since you haven't actually tried it the correct way I can not assure you that it does actually work.

Good luck and keep the reports up, they provide us with details that you missed from the examples. It helps debugging what went wrong :)

@corysimmons
Copy link

@SidOfc Sorry I should've mentioned that I tried all of your suggestions in order, verbatim, before posting my screenshot above. No luck. :(

@joemsak
Copy link

joemsak commented Aug 22, 2018

okay, sorry, you're right I missed your full instructions

However, I do expect to just be able to update npm from wherever i'm using a .tool-versions file though

Anyway, I have done as instructed and still face this issue. I am on 10.14 beta now but these issues had persisted on 10.13 stable. No other unix or OS based issues have come up for me and this is my primary development machine.

~ % cd ~/.asdf/installs/nodejs/10.7.0/lib
lib HEAD % npm i npm
npm WARN saveError ENOENT: no such file or directory, open '/Users/joemsak/.asdf/installs/nodejs/10.7.0/lib/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/Users/joemsak/.asdf/installs/nodejs/10.7.0/lib/package.json'
npm WARN lib No description
npm WARN lib No repository field.
npm WARN lib No README data
npm WARN lib No license field.

+ npm@6.4.0
added 12 packages from 9 contributors, removed 35 packages, updated 23 packages and audited 5003 packages in 9.814s
found 0 vulnerabilities

lib HEAD % npm -v
6.2.0
lib HEAD % asdf reshim nodejs
lib HEAD % npm -v
6.2.0
lib HEAD % node -v
v10.7.0

@SidOfc
Copy link

SidOfc commented Aug 22, 2018

@corysimmons I checked your screenshot and I've also seen this error come by sometimes. I am however unsure how exactly I fixed those scenario's as it has been a while since I've last encountered it. The only thing I can really tell you is that I kept juggling with the above commands and somehow it started working (blergh, I hate giving inconclusive advice...) :(

@joemsak no need to apologize, you have my apologies if it sounded harsh :)
I wanted to put some extra emphasis on the absolutely required steps here that's all, most of the time the devil is in the details and they can be crucial to debugging :)

The behaviour you are describing should be possible too I think. One can just run npm i npm --save-dev inside any project which would make npm a dependency of that project.

I just tried this in one of my projects which uses Node. I am using npm version 5.5.1 locally and ran the above command (npm i npm --save-dev) followed by a asdf reshim nodejs to no avail. While the correct npm version 6.4.0 does get installed, it is simply not being recognized at all. Sample output:

$ cd /relevant/directory
$ npm -v
# => 5.5.1
$ npm i npm --save-dev
# => correctly installs npm 6.4.0 without errors
$ npm -v
# => 5.5.1
$ asdf reshim nodejs
$ npm -v
# => 5.5.1

I then started up a fresh shell session and did a cd into that directory and retried the version command npm -v which still returned 5.5.1.

It is definitely not your build @joemsak, nor your fault at all. All this black magic we have to perform simply makes no sense if you aren't actually managing such plugin interfaces. I barely have the knowledge to fix these issues myself, it is often a mystery to me.

Perhaps we can take a more in-depth look into this by checking how this is handled, I'm quite busy currently but this is a long standing issue that could use some fresh infos so I'll see if I can put something together anytime soon.

Meanwhile, just make sure you keep everything up-to-date and retry the above steps. Sometimes doing a complete uninstall and reinstall can fix some problems.

Update oneliner:

$ asdf update && asdf plugin-update --all

Fish oneliner:

$ asdf update; and asdf plugin-update --all

Unfortunately, this is the best advice I can give at this time :/

Sid

@corysimmons
Copy link

@SidOfc Appreciate your help but I'm done with nvm, asdf, etc. etc. etc. etc.

I'll just have to manually remember to switch Node versions for certain projects and use $ n instead of fighting tooling.

@SidOfc
Copy link

SidOfc commented Sep 15, 2018

Update

I have been able to update npm after running asdf update --head. I'm now running v0.5.1 and can confirm that on Node v9.1.0 with npm v5.5.1, running the command npm i -g npm correctly installs v6.4.1 (even without reshimming).

@Stratus3D
Copy link
Member

Sorry to have been so absent from this discussion. Is anyone still having issues with this?

@joemsak
Copy link

joemsak commented Oct 8, 2018

@SidOfc seems like it's working okay for me after your oneliner

@SidOfc
Copy link

SidOfc commented Oct 9, 2018

Good to hear @joemsak!

@Stratus3D I am not sure there, few folks have been active on this issue so maybe it can be closed as it seems to be working in the latest version for macOS at least.

@mhubig
Copy link

mhubig commented Oct 23, 2018

A simple npm config set scripts-prepend-node-path true solved it for me.

@DevotionGeo
Copy link

While it is a somewhat older issue, using asdf reshim nodejs <your-installed-version> fixed this for me on macOS 10.12.6 (Sierra). If it doesn't, try this afterwards: source ~/.zshrc or source ~/.bashrc.

It saved my day. Thank you!

@ar-to
Copy link

ar-to commented Dec 8, 2021

my issue was similar to others above but turns out it was a missing lib directory. I was careful to try some of the suggestions above to avoid making it worse but yes re-installing did not work.

Replace {user} with the name of your directory.

The error was like:

❯ npm install --global yarn
npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path /Users/{user}/.asdf/installs/nodejs/15.5.0/.npm/lib
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, lstat '/Users/{user}/.asdf/installs/nodejs/15.5.0/.npm/lib'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/{user}/.npm/_logs/2021-12-08T19_38_07_657Z-debug.log

The solution was to manually create the directory and try again.

 mkdir /Users/{user}/.asdf/installs/nodejs/15.5.0/.npm/lib
# then tried again and it worked
❯ npm install --global yarn

added 1 package, and audited 2 packages in 897ms

found 0 vulnerabilities
Reshimming asdf nodejs...

# checked
❯ yarn --version
1.22.17
❯ which yarn
/Users/ArielGuzman/.asdf/shims/yarn

My question is what happened that caused this directory to not be included upon install?

@jthegedus
Copy link
Contributor

@ar-to The plugin for the tool is what decides what files are installed so your question is best raised as a new issue on the asdf-nodejs plugin repo.

@JeanBarbosa27
Copy link

Hmmn that is unfortunate @joemsak, I usually do a reshim without version but when in doubt, I try it with the version included: asdf reshim nodejs 9.11.1. It could also be that the nodejs you're running might not be managed by asdf. This can be checked by running which node and which npm, it should be something like this:

image

Also, which version of asdf are you running? If a version-specific reshim doesn't work, perhaps it might help to update your plugins and/or asdf itself. I remember running into some issues using an older version of the asdf nodejs plugin.

  • plugins: asdf plugin-update --all
  • asdf: asdf update

As a last resort I would try reinstalling said Node version, I did this a few times for Node myself so you're not alone in these issues :)

  • To remove old node: asdf plugin-remove nodejs.
  • Ensure that the ~/.asdf/installs/nodejs folder is also removed, if it isn't, run rm -rf ~/.asdf/installs/nodejs/9.11.1.
  • Reinstall node: asdf install node 9.11.1 asdf plugin-add nodejs.
  • Reinstall specific Node version asdf install nodejs 9.11.1
  • Restart everything, kill zsh, any tmux/screen sessions, your terminal and see if it works.

Let me know what happens, good luck +1

I got an issue trying to create a global command to a CLI using npm link command (the link wasn't beeing done), but the * plugins: asdf plugin-update --all ad * asdf: asdf update commands solved it. Thanks SidOfc

@sespinoza-dev
Copy link

I see some time ago you had the same issue with node 9.9.0 here on asdf-vm/asdf-nodejs#56. The command for me mentioned by @dipnlik correctly installed latest version of npm for me:

cd ~/.asdf/installs/nodejs/[VERSION]/lib && npm i npm

note: Do not forget to change "[VERSION]" with the actual nodejs version.

Could you try and see if maybe this does work for 9.11.1? One can hope ;)

Thank you, this fixed my issues when installing node v20.11.1 in Ubuntu 22.04.5 LTS (Jammy Jellyfish)
I also had to update my asdf version with asdf update && asdf plugin-update --all.

$ asdf update && asdf plugin-update --all
$ cd ~/.asdf/installs/nodejs/20.11.1/lib && npm i npm

I was having the following error:

$ npx nodemon
npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path /home/user/.asdf/installs/nodejs/20.11.1/.npm
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, lstat '/home/user/.asdf/installs/nodejs/20.11.1/.npm'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in: /home/user/.npm/_logs/2024-11-10T13_04_50_319Z-debug-0.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests