NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.69k stars 13.83k forks source link

Package npm separately, or allow override in nodejs packages #129632

Open osslate opened 3 years ago

osslate commented 3 years ago

Package npm separately, or allow override in nodejs packages Apologies if this is easily possible via configuration (I'm new to Nix), but I couldn't find any searching through nodejs.nix and related files.

The nodejs package allows me to pick whether I want npm to be installed as it is bundled with the nodejs distribution, but there doesn't appear to be an option to specify a different version of npm. Personally, this is useful as a stack I work with runs on node.js v14, but requires features that aren't available in the bundled version of npm (workspaces).

Due to the way nix works, I can't do npm i -g npm to upgrade as I would on other systems, so this needs to be done via nix.

I'm proposing that npm be packaged separately to allow installation of a specific version of node.js and a specific version of npm (so long as they're compatible).

Metadata

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

aisamu commented 2 years ago

I just ran into a similar issue! The quick "fix" was to add nodePackages.npm explicitly (and before node), but suspect this might have other implications/have limited applicability.

montchr commented 1 year ago

Surprisingly, this unfortunate combination of nodejs/npm versions is still sometimes a requirement, especially in large or agency projects that got tripped up by the npm@7 lockfile schema changes and decided to stay on npm@6 despite it being a terrible downgrade.

One prominent example:

https://github.com/WordPress/gutenberg/blob/0c894c2843bba9cf0b47e18b7c136444e9616172/package.json#L18-L19

Although I prefer to use Nix for this kind of thing, it still seems that mixing and matching Node/npm versions is still either unsupported(?) or its method of attainment still obscure (nothing popped out at me in the manual).

montchr commented 10 months ago

~I'm back again after realizing that there doesn't seem to be any way of installing the current version of npm with a stable version of node. Node 20 ships with npm v9, but the most recent version of npm is v10.~ No, I am wrong -- nodejs_20 comes with npm v10. For some reason I was stuck on an old pinned version of nixos-unstable.

Edit: I am not really sure how I would go about fixing this, since it's a structural issue whose fix could cause mass rebuilds and would probably require some planning to figure out how to avoid breaking changes.

Edit 2: I wonder if there other languages supported in Nixpkgs with their own package managers whose versions can be changed independently, for which we could use as prior art for addressing the issue here. It looks like PHP suffers from the same issue -- its package manager Composer should not be tied to specific PHP versions, but similarly to Node, is available as e.g. php81Packages.composer.

montchr commented 10 months ago

The quick "fix" was to add nodePackages.npm explicitly (and before node), but suspect this might have other implications/have limited applicability.

If this provided a fix to get the desired version of npm, that would only be by coincidence based on the version bundled with that particular version of nodejs.