Skip to content

Enable Corepack #480

Closed
Closed

Description

@shellscape

Description:

Related to this issue and comment #182 (comment), I'd like to see support for enabling corepack without having to have a separate run step to do so.

Justification:

This would reduce overall runtime of actions, as no separate steps are required to enable corepack nor to install package managers, which is a net benefit to users in both regards.

Are you willing to submit a PR?

Surely

Activity

  1. e-korolevskii commented on May 4, 2022

    @e-korolevskii
    Contributor

    Hi @shellscape,
    We will investigate the possibility of adding this feature.

  2. e-korolevskii commented on May 4, 2022

    @e-korolevskii
    Contributor

    Hi @shellscape,
    Unfortunately, corepack is experimental now, so we would not implement that at least while its not become stable.
    That is why I will close this issue now. If you have any questions or concerns, please feel free to leave a comment on this thread or open another issue.

  3. shellscape commented on May 4, 2022

    @shellscape
    Author

    Hm, I don't see anything codified in this repo that states experimental features aren't welcome. Seems that a experimental property would be a very good fit here. I think this was closed prematurely.

  4. styfle commented on May 4, 2022

    @styfle

    A PR was already started in #482

    Also, we should get clarity around the path from experimental to stable nodejs/corepack#104

  5. shellscape commented on May 4, 2022

    @shellscape
    Author

    @styfle ah I missed that, thanks for pointing it out. I'll continue discussion there.

  6. dmitry-shibanov commented on May 4, 2022

    @dmitry-shibanov
    Contributor

    Hello @shellscape. I think the main reason to not enable corepack by default because some customers can use setup-node with cache enable in conjunction with pnpm/action-setup before setup-node. When corepack is enabled it will override preinstalled pnpm (from pnpm/action-setup).
    For example users can specify use the latest version of pnpm (7th), but corepack can override it to 6th. This also applies to yarn.

  7. Ethan-Arrowood commented on May 4, 2022

    @Ethan-Arrowood

    corepack will not override it to 6 unless that is what is set for packageManager

  8. dmitry-shibanov commented on May 4, 2022

    @dmitry-shibanov
    Contributor

    Hello @Ethan-Arrowood. Thank you for your response. I've tried to use this snippet and it overrides pnpm version.

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2
        with:
          version: 7
      - run: pnpm --version
      - uses: actions/setup-node@v3
        with:
          node-version: 16.9.0
      - run: |
          corepack enable
          pnpm --version
    
  9. Ethan-Arrowood commented on May 4, 2022

    @Ethan-Arrowood

    Is packageManager in your package.json set to pnpm@7.0.0?

  10. dmitry-shibanov commented on May 4, 2022

    @dmitry-shibanov
    Contributor

    Is packageManager in your package.json set to pnpm@7.0.0?

    No it does not. With packageManager it works as expected. But not all users have packageManager field, that is why it can break existing behaviour some users if corepack is enabled by default with caching.

  11. viceice commented on May 5, 2022

    @viceice

    Hello @Ethan-Arrowood. Thank you for your response. I've tried to use this snippet and it overrides pnpm version.

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2
        with:
          version: 7
      - run: pnpm --version
      - uses: actions/setup-node@v3
        with:
          node-version: 16.9.0
      - run: |
          corepack enable
          pnpm --version
    

    it makes no sense to setup pnpm before node. 🤔

  12. 6 remaining items

  13. naXa777 commented on Nov 21, 2023

    @naXa777

    is this change released?

    Now for users who used a separate step to enable corepack, the github action is broken. Hence the declared goal of this change request is not met: "which is a net benefit to users in both regards".

    sample yaml:

    jobs:
      test:
        steps:
          - name: Checkout code
            uses: actions/checkout@v3
    
          - name: Setup Node.js
            uses: actions/setup-node@v3
            with:
              node-version: '18'
              cache: 'yarn'
    
          - name: Enable corepack
            run: |
              corepack enable
              corepack prepare yarn@3.5.1 --activate
              yarn set version 3.5.1
    

    The step "Setup Node.js" fails with error:

    error This project's package.json defines "packageManager": "yarn@3.3.1". However the current global version of Yarn is 1.22.21.
    
    Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.[19](https://github.com/Found-ee/react-ui/actions/runs/6940271054/job/18878934903#step:3:21).
    Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.
    Error: error This project's package.json defines "packageManager": "yarn@3.3.1". However the current global version of Yarn is 1.22.[21](https://github.com/Found-ee/react-ui/actions/runs/6940271054/job/18878934903#step:3:23).
    
    Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
    Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.
    

    The step "Enable corepack" that follows is not executed, cause the action is already failed.

  14. darkbasic commented on Nov 21, 2023

    @darkbasic

    Yeah I've noticed that as well. Initially it started happening randomly and re-triggering the CI fixed it, but now it happens consistently. The solution is to enable corepack before setup-node. I hope that one day setup-node will officially support corepack and such hacks won't be necessary anymore.

  15. BeroBurny commented on Nov 21, 2023

    @BeroBurny

    like we had cache: 'yarn' in config

          - name: Set up Node.js
            uses: actions/setup-node@v3
            with:
              node-version: "18"
              cache: 'yarn'

    after removing it solved the problem 🤷‍♂️
    but found it after applied @darkbasic solution

  16. dylants commented on Jan 29, 2024

    @dylants

    Explicitly putting together what others have said, this worked for me:

    name: CI
    
    on:
      push:
        branches: [main]
      pull_request:
        branches: [main]
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - uses: actions/checkout@v4
          - name: Enable Corepack
            run: corepack enable
          - name: Use Node.js 20.x
            uses: actions/setup-node@v4
            with:
              node-version: "20.x"
              cache: 'yarn'
          - name: Install dependencies
            run: yarn install --immutable
          - name: Run lint
            run: yarn lint
          - name: Run tests
            run: yarn test
          - name: Run build
            run: yarn build
  17. shawnmclean commented on Jun 24, 2024

    @shawnmclean

    man, how come I have to find these things in a gh issue?

    Is this officially documented anywhere?

    I'm in the process of upgrading something to yarn 4 from 1 and couldn't find anything on github actions.

  18. added a commit that references this issue on Sep 20, 2024
  19. added a commit that references this issue on Nov 21, 2024
  20. SethFalco commented on May 25, 2025

    @SethFalco

    Thanks, @dylants, for sharing your solution in #480 (comment). It did not work for me as-is, however did resolve the immediate problem, which helped me get to a final solution for my project.

    I have a library, where all unit tests are run on a matrix of Windows and Linux, and then also for Node.js v16, v18, v20, and v22.

    Dylan's solution worked for the following:

    Linux Windows
    Node.js v16 ❌ ❌
    Node.js v18 ✅ ❌
    Node.js v20 ✅ ❌
    Node.js v22 ✅ ❌

    To fix runs on Linux with Node.js v16, I had to override the version of corepack to v0.20.0, the latest version available with Node.js v16 support, instead of using the one bundled with Node.js:

          steps:
            - uses: actions/checkout@v4
    +       - run: npm install -g corepack@0.20.0
            - run: corepack enable
            - uses: actions/setup-node@v4
              with:
                node-version: ${{ matrix.node-version }}
                cache: yarn
            - run: yarn install
    Linux Windows
    Node.js v16 ✅ ❌
    Node.js v18 ✅ ❌
    Node.js v20 ✅ ❌
    Node.js v22 ✅ ❌

    Then to fix things for Windows, I had to add --force to let npm know it can replace the global version of Yarn:

          steps:
            - uses: actions/checkout@v4
    -       - run: npm install -g corepack@0.20.0
    +       - run: npm install -g corepack@0.20.0 --force
            - run: corepack enable
            - uses: actions/setup-node@v4
              with:
                node-version: ${{ matrix.node-version }}
                cache: yarn
            - run: yarn install
    Linux Windows
    Node.js v16 ✅ ✅
    Node.js v18 ✅ ✅
    Node.js v20 ✅ ✅
    Node.js v22 ✅ ✅

    Reference: svg/svgo#2138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or request to improve the current logic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions