CircleCI-Public / node-orb

An orb for working with Node.js on CircleCI
https://circleci.com/orbs/registry/orb/circleci/node
MIT License
54 stars 81 forks source link

Installing yarn-berry does not seem to work #217

Closed adamretter closed 1 month ago

adamretter commented 5 months ago

Orb version: 5.2.0

What happened:

I want to use Yarn version 4.2.2 (or thereabouts) and so I have followed the yarn_berry_zero_install example from the documentation, and have this config:

jobs:
  clone-and-install:
    docker:
      - image: cimg/node:20.1.0
    resource_class: small
    steps:
      - checkout
      - node/install-packages:
          check-cache: always
          cache-version: v4
          pkg-manager: yarn-berry
          with-cache: false

When this runs I get the following error output in CirceCI (see: https://app.circleci.com/pipelines/github/evolvedbinary/lwdita/473/workflows/ffcd9a7e-e3c1-4504-b11c-29256fee42c6/jobs/1674):

yarn install v1.22.19
[1/5] Validating package.json...
error @evolvedbinary/lwdita@0.2.4: The engine "yarn" is incompatible with this module. Expected version ">=4.2.2". Got "1.22.19"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Exited with code exit status 1

As I have set pkg-manager: yarn-berry I don't understand why it is still trying to use Yarn Classic (i.e. 1.x.x).

Expected behavior:

It should use version 4.2.2 of Yarn.

nicklozon commented 3 months ago

The install command is where you specify what version of yarn you'd like to use, but it doesn't work for yarn-berry since it only references the classic builds.

In order to use yarn-berry I found the best way is to use Corepack. Here's a snippet of my config;

commands:
  build:
    steps:
      - run:
          name: Enable Corepack
          command: corepack enable
      - node/install-packages:
          pkg-manager: yarn-berry

I believe yarn will automatically use the version specified by packageManager in your package.json. YMMV depending on what node version you're using.

CircleCI should add some documentation for using yarn berry. I think simply using Corepack is the best approach, but would love to know what others do.

marboledacci commented 2 months ago

This issue should be fixed in the new version https://circleci.com/developer/orbs/orb/circleci/node?version=6.1.0. Note: for yarn-berry to work, the version must be specified in the package.json

adamretter commented 1 month ago

Thank you very much @marboledacci