How to run `corepack enable` to install Yarn berry?

4.1k views Asked by At

For modern versions of Yarn, aka Yarn Berry, the preferred installation is through Corepack, and Corepack is included by default with Node.js installs (>=16.10). See https://yarnpkg.com/getting-started/install

This is what I've tried to do corepack enable in default.nix, but it doesn't work.

with import <nixpkgs> {};

stdenv.mkDerivation {
  name = "dev";
  dontUnpack = true;
  buildInputs = [ nodejs-17_x ];
  postPhases = ''
    corepack enable
  '';
}
1

There are 1 answers

1
PAStheLoD On

For anyone else who ends up here via a search engine :)

corepack enable

corepack prepare [email protected] --activate

(enable is needed to install the symlinks, and prepare + activate sets the correct version.)

This should work on v16.9.0+ (and even v14.19.0+)

source: https://nodejs.org/api/corepack.html#upgrading-the-global-versions