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

yarn package pins nodes 8 and ignores node 10 installed via default.nix #53820

Closed
JohannesRudolph opened this issue Jan 12, 2019 · 4 comments
Closed

Comments

@JohannesRudolph
Copy link
Contributor

Issue description

Beware, new nix user here so this may be entirely my fault. Apparently, the "yarn" package gets its own nodes version and ignores the nodejs version configured in the default.nix file.

I have tried finding docs on how to control a possible "indirect" dependency but couldn't figure this out.

Steps to reproduce

I have this default.nix file

with import <nixpkgs> {};
stdenv.mkDerivation rec {
  name = "env";
  env = buildEnv { name = name; paths = buildInputs; };
  buildInputs = [
    yarn
    nodejs-10_x
  ];
}

Running yarn however for a package.json that restricts

  "engines": {
    "node": "^10.12.0"
  }

results in an error.

[nix-shell:~/dev/mc/meshfed-release/panel]$ yarn
yarn install v1.12.3
[1/5] 🔍  Validating package.json...
error [email protected]: The engine "node" is incompatible with this module. Expected version "^10.12.0". Got "8.14.1"
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
[nix-shell:~/dev/mc/meshfed-release/panel]$ node --version
v10.12.0

Technical details

Please run nix-shell -p nix-info --run "nix-info -m" and paste the
results.

 - system: `"x86_64-darwin"`
 - host os: `Darwin 18.2.0, macOS 10.14.1`
 - multi-user?: `no`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.1.3`
 - channels(jrudolph): `"nixpkgs-19.03pre165281.7d864c6bd63"`
 - nixpkgs: `/Users/jrudolph/.nix-defexpr/channels/nixpkgs`
@marsam
Copy link
Contributor

marsam commented Jan 12, 2019

you need to override the nodejs version used by yarn https://nixos.org/nixos/nix-pills/nixpkgs-overriding-packages.html

--- i/shell.nix
+++ w/shell.nix
@@ -3,7 +3,7 @@ stdenv.mkDerivation rec {
   name = "env";
   env = buildEnv { name = name; paths = buildInputs; };
   buildInputs = [
-    yarn
+    (yarn.override { nodejs = nodejs-10_x; })
     nodejs-10_x
   ];
 }

@JohannesRudolph
Copy link
Contributor Author

Thanks @marsam, that did the job! Looks like there's some good stuff in nix-pills that's not immediately apparent from the main docs.

@jaredramirez
Copy link
Contributor

For anyone else using nvm:
With nvm, you can't have any version of node to be installed with yarn. To solve this, you can do: (pkgs.yarn.override { nodejs = null; })

@jfly
Copy link
Contributor

jfly commented May 22, 2023

For anyone else who usese @jaredramirez's trick, it is broken after this change: 4369da1:

$ nix-shell -p '(pkgs.yarn.override { nodejs = null; })'
error: value is null while a set was expected

       at /nix/store/gl5k534l2h2msyd38i179zfpxfid1hjm-h2mn9hkw60rhlv4fyhz287127dim9r01-source/pkgs/development/tools/yarn/default.nix:38:17:

           37|     maintainers = with maintainers; [ offline screendriver marsam ];
           38|     platforms = nodejs.meta.platforms;
             |                 ^
           39|   };
(use '--show-trace' to show detailed location information)

The fix I'm using is to also override meta.platforms:

$ nix-shell -p '(pkgs.yarn.override { nodejs = null; }).overrideAttrs (oldAttrs: { meta.platforms = nodejs.meta.platforms; })'

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

4 participants