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

Cannot install package manager using corepack on node 16 #10036

Closed
4 of 14 tasks
SunsetTechuila opened this issue Jun 10, 2024 · 8 comments
Closed
4 of 14 tasks

Cannot install package manager using corepack on node 16 #10036

SunsetTechuila opened this issue Jun 10, 2024 · 8 comments

Comments

@SunsetTechuila
Copy link

SunsetTechuila commented Jun 10, 2024

Description

No matter on what node version you are, the latest corepack will be used. The problem is that the latest corepack tries to use node's built-in fetch, which is not available in node 16

This is a quite common problem

Platforms affected

  • Azure DevOps
  • GitHub Actions - Standard Runners
  • GitHub Actions - Larger Runners

Runner images affected

  • Ubuntu 20.04
  • Ubuntu 22.04
  • Ubuntu 24.04
  • macOS 11
  • macOS 12
  • macOS 13
  • macOS 13 Arm64
  • macOS 14
  • macOS 14 Arm64
  • Windows Server 2019
  • Windows Server 2022

Image version and build link

ubuntu-24.04 20240604.1.0

failed workflow run

Is it regression?

ubuntu-22.04 20240324.2.0 was working fine - https://github.com/import-js/eslint-import-resolver-typescript/actions/runs/8502297529/job/23286295001

Expected behavior

I expect the chosen package manager to be installed

Actual behavior

Error: Error when performing the request to https://registry.npmjs.org/yarn/latest; 
  [cause]: TypeError: globalThis.fetch is not a function
      at fetch (/usr/local/lib/node_modules/corepack/dist/lib/corepack.cjs:22756:33)

Repro steps

  1. Set the packageManager filed in the package.json file
  2. Create a workflow containing these steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
  with:
    node-version: 16
  1. Run workflow

Or:

  1. Fork this repo
  2. Run the Showcase workflow
@kishorekumar-anchala
Copy link
Contributor

Hi @SunsetTechuila , We're working on your issue , will provide the solution as soon as possible . Thank you for your support !

@kishorekumar-anchala
Copy link
Contributor

Hi @SunsetTechuila ,

i have seen your package.json file , there is some syntax issue . i made some significant changes in package.json file as below

{
"name": "core-pack",
"version": "1.0.0",
"packageManager": "corepack",
"devDependencies": {
"pnpm": "~8.14.2"
}
}

as per your package.json file , you're using pnpm as dependency so we need to install that dependency . kindly look into below workflow as per your repro steps i build and got succeeded.

` - name: Install PNPM
run: npm install -g pnpm

  - name: Install node-fetch for Corepack
    run: pnpm install node-fetch || npm install node-fetch

  - name: Setup globalThis.fetch for Corepack
    run: echo "globalThis.fetch = require('node-fetch');" >> $GITHUB_ENV

  - name: Enable Corepack
    run: corepack enable

  - name: Setup Node.js ${{ matrix.node }}
    uses: actions/setup-node@v4
    with:
      node-version: ${{ matrix.node }}` 

Try to re-produce with above workaround , if any issue feel free to revert us .

@kishorekumar-anchala
Copy link
Contributor

Hi @SunsetTechuila ,

Hope you have tried above work around , please share your comments on your issue ?

@SunsetTechuila
Copy link
Author

SunsetTechuila commented Jun 12, 2024

hello

there is some syntax issue

no, my package.json is completely fine
the name and version fields are only necessary when publishing a package
about the packageManager field - https://nodejs.org/api/packages.html#packagemanager

"packageManager": "corepack",

this is not a valid value, please check this link and above

you're using pnpm as dependency so we need to install that dependency

run: npm install -g pnpm

you don't have to manually install package managers, that's the whole point of Corepack
see https://yarnpkg.com/corepack for an explanation

also there are better workarounds for this:

and in the end, all of this are only workarounds, which weren't necessary a few months ago

@kishorekumar-anchala
Copy link
Contributor

Hi @SunsetTechuila ,

Thank You for your quick reply on it , in my observation you're getting compatibility issue as node 16 will not support the latest corepack manager version, so i tried to install it manually .

I hope your issue got resolved with above workarounds in your case, Please confirm from your end to proceed further step.

@SunsetTechuila
Copy link
Author

SunsetTechuila commented Jun 13, 2024

in my observation you're getting compatibility issue as node 16 will not support the latest corepack manager version

Yes, that's what I said in the description

This issue can't be reproduced on local machine because Node ships with the compatible version of Corepack. You can verify this by following these steps:

  1. Download prebuilt binaries of v16.20.2 from the Node's site
  2. Unpack the downloaded archive
  3. Open the lib/node_modules/corepack/dist/corepack.js file
  4. Search for var version =

You will see that it is 0.17.0, which is not the latest build

I hope your issue got resolved with above workarounds in your case,

Yes, it was

@SunsetTechuila
Copy link
Author

SunsetTechuila commented Jun 13, 2024

@kishorekumar-anchala hello, can i ask you why have you closed the issue?

As I said:

> This issue can't be reproduced on local machine because Node ships with the compatible version of Corepack

I expect the same from the github-hosted runners

@SunsetTechuila
Copy link
Author

SunsetTechuila commented Jun 13, 2024

update:

no, my package.json is completely fine

no, it wasn't. didn't notice the leading @ in the packageManager field, sorry (however, this changes nothing)

the latest corepack will be used

happens because I run corepack enable before setting up Node, so this nothing to do with runners

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

No branches or pull requests

2 participants