Code Monkey home page Code Monkey logo

Comments (13)

dipnlik avatar dipnlik commented on May 30, 2024 26

cd ~/.asdf/installs/nodejs/8.8.1/lib && npm i npm looks like a decent workaround for now, but I'm not sure of the side effects, if any.

from asdf-nodejs.

andrewthauer avatar andrewthauer commented on May 30, 2024 8

It turns out the NPM_CONFIG_PREFIX is the crux of the issue here. Removing the exec-env file fixes this and #57. Removing it will make the plugin behave like nvm & nodenv by default and avoid the issue altogether.

@tuvistavie, @Stratus3D, @HashNuke - I personally can't think of a strong reason to support NPM_CONFIG_PREFIX in this plugin can you?

There still would be the issue of pre-existing installs and shims that would likely cause breaking changes if it's removed completely. Given that the existing shims would be using the prefix, it seems like it could be difficult to address without breaking changes.

from asdf-nodejs.

rstacruz avatar rstacruz commented on May 30, 2024 1

I added a workaround that works for now (as of 2018-05-24): #57 (comment)

This is not ideal, but it should at least make it work to get you out of possibly-insecure legacy npm versions.

from asdf-nodejs.

danhper avatar danhper commented on May 30, 2024

Hi, thanks for reporting.
I managed to reproduce the issue locally. The issue seems to be that we have a npm binary in nodejs/installs/VERSION/bin and another one in nodejs/installs/VERSION/.npm/bin. The second should take priority but does not.
I do not have much time to work on this right now, so help is very welcome.

from asdf-nodejs.

mareksuscak avatar mareksuscak commented on May 30, 2024

@tuvistavie no problem, happy to contribute, can you give me some pointers on where to start and briefly describe how the solution should work? i'm not familiar with the codebase ATM so that would be super helpful, thx for looking into this!

from asdf-nodejs.

danhper avatar danhper commented on May 30, 2024

@mareksuscak Thank you!
The problem is in the reshim command, which does not rewrite the shim as it already exists.
https://github.com/asdf-vm/asdf/blob/master/lib/commands/reshim.sh#L59
However, as the existing shim is pointing to nodejs/installs/VERSION/bin and the new one should point to nodejs/installs/VERSION/.npm/bin, it does not work as expected.

However, after thinking about it, this is a little more complicated than it looks.
As long as we stick with a single version, we would simply need to rewrite the shim, but for a case where a version of NodeJS should use .npm/bin/npm and another does not have .npm/bin/npm but only bin/npm, I do not see any clean way to handle this with the current interface.
@asdf-vm/maintainers Any idea on how we should handle this?
By the way, why are we using .npm as NPM_PREFIX and not simply the root of the installation?

from asdf-nodejs.

jschank avatar jschank commented on May 30, 2024

I have this problem too. What if:

  1. There were an 'asdf exec' sub-command, that essentially did the switch to the current install directory, and ran the passed command?
  2. There were an 'asdf upgrade ' command, supported by the plugins that would manage this sort of task?

I'm using the work-around for now. But it will be easy to forget this, by the time I need to do it again.
:)

Thanks

from asdf-nodejs.

adsteel avatar adsteel commented on May 30, 2024

Running into this issue as well. MacOS High Sierra 10.13.1.

FWIW I experienced this issue on Nodenv, first. I switched to ASDF (a good excuse to switch, anyway) to fix it, but the problem persisted.

from asdf-nodejs.

joemsak avatar joemsak commented on May 30, 2024

The workaround didn't work for me, nodejs 9.9.0

from asdf-nodejs.

andrewthauer avatar andrewthauer commented on May 30, 2024

Perhaps it might make sense to automatically install npm (e.g. npm i -g npm@[shipped-version]) when a new version of nodejs is installed? Then if the plugin's list-bin-path is swapped from bin .npm/bin to .npm/bin bin the reshim will correctly write npm to use .npm/bin. It would also guarantee all versions of nodejs have npm installed as a node_module in .npm/bin.

This would likely work for anyone starting fresh (with the updated plugin). However, since shims are not recreated if they exist, it would require someone that has an older setup to manually fix it up (i.e. remove the previous shim). I suppose it would also break if someone uninstalled npm global for some reason as well.

from asdf-nodejs.

mareksuscak avatar mareksuscak commented on May 30, 2024

@andrewthauer that sounds totally reasonable, at least as a temporary fix

from asdf-nodejs.

andrewthauer avatar andrewthauer commented on May 30, 2024

I think the only way to avoid running into some of these outlier cases there must be a conditional check somewhere. In order to do this it's likely going to require some sort of plugin customization hook support in asdf core since shim generation has very limited knowledge about the plugin language (as it should not).

I think this might be a possible solution to the problem ...

Provide an optional plugin hook that is used by the get_executable_path function (which is called by asdf-exec). This would then need to check if the plugin (e.g. nodejs) has an alternate command path for the specified shim command (e.g. npm). For instance the nodejs plugin would use .npm/bin/npm if it exists or fallback to bin/npm if not.

from asdf-nodejs.

andrewthauer avatar andrewthauer commented on May 30, 2024

I ended up created a couple of PR's to address this #74 (which will work if accepted). I had a look at how nodenv works and handles this. There is actually no special handling at all. The root cause actually lies in how the node version install is setup by the asdf-nodejs plugin:

A stock node binary install has a lib/node_modules directory which contains npm with the command linked to bin/npm. The asdf-nodejs plugin also does this. However the difference is the plugin also adds an .npm/lib/node_modules & .npm/bin directory for any globally installed packages. In the case of npm this ends up creating 2 different locations for the npm command.

nodenv on the other hand installs global packages the root lib/node_modules directory, which seems to be the standard location (further investigation is warranted). This means there is only ever one instance of any global package (including npm). The actual fix, might just be adjusting how node versions are installed to correspond to what seems to be the stock pattern.

from asdf-nodejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.