How to run `corepack enable` to install Yarn berry?
Asked Answered
L

1

5

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
  '';
}
Lebanon answered 22/4, 2022 at 16:30 Comment(1)
https://mcmap.net/q/761886/-not-able-to-install-yarn-through-corepack this answer helped me fix same problemGlialentn
J
6

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

Jupon answered 22/4, 2022 at 16:30 Comment(3)
for me, I had EACCESS issue. So sudo corepack enable did the trickSharkey
"EROFS: read-only file system, symlink […]" on NixOS unstable.Lowtension
NixOS users need to use use the corepack nix package, or a nix-shell (with ephemeral packages) see discourse.nixos.org/t/install-pnpm-as-standalone/31841/5Jupon

© 2022 - 2024 — McMap. All rights reserved.