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

yarn init ignores global default version #589

Open
MikeMcC399 opened this issue Jan 12, 2025 · 0 comments
Open

yarn init ignores global default version #589

MikeMcC399 opened this issue Jan 12, 2025 · 0 comments

Comments

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Jan 12, 2025

Current behavior

If an alternate version of Yarn Modern is installed through corepack install --global, for instance [email protected], the command yarn init, in an empty project directory, attempts to install Yarn Modern 4.5.2.

Desired behavior

If an alternate version of Yarn Modern is installed through corepack install --global, the command yarn init, in an empty project directory, should use the globally installed version, as shown in ~/.cache/node/corepack/lastKnownGood.json.

Corepack documentation Upgrading the global versions specifically mentions yarn init as an example to override the default version.

Environment / versions

Ubuntu 24.04.1 LTS, Node.js 23.6.0
corepack 0.30.0
Using n as Node.js manager

Steps to reproduce

corepack disable
rm -rf ~/.cache/node/corepack
corepack enable yarn
corepack install --global [email protected]
cat ~/.cache/node/corepack/lastKnownGood.json

mkdir yarn-init-test
cd yarn-init-test
yarn -v
yarn init -y

Logs

$ corepack disable
rm -rf ~/.cache/node/corepack
corepack enable yarn
corepack install --global [email protected]
cat ~/.cache/node/corepack/lastKnownGood.json

mkdir yarn-init-test
cd yarn-init-test
yarn -v
yarn init -y
Installing [email protected]...
{
  "yarn": "4.0.0"
}
4.0.0
! Corepack is about to download https://repo.yarnpkg.com/4.5.2/packages/yarnpkg-cli/bin/yarn.js
? Do you want to continue? [Y/n]

Debug logs

export DEBUG=corepack
$ yarn -v
  corepack LastKnownGood file would be located at /home/mike/.cache/node/corepack/lastKnownGood.json +0ms
  corepack Search for default version: Found [email protected] in LastKnownGood file +2ms
  corepack Checking /home/mike/github/yarn-init-test/package.json +0ms
  corepack Checking /home/mike/github/package.json +0ms
  corepack Checking /home/mike/package.json +0ms
  corepack Checking /home/package.json +0ms
  corepack Checking /package.json +1ms
  corepack Falling back to [email protected] as no project manifest were found +0ms
  corepack Reusing [email protected] found in /home/mike/.cache/node/corepack/v1/yarn/4.0.0 +8ms
4.0.0
$ yarn init -y
  corepack LastKnownGood file would be located at /home/mike/.cache/node/corepack/lastKnownGood.json +0ms
  corepack Search for default version: Found [email protected] in LastKnownGood file +2ms
  corepack Checking /home/mike/github/yarn-init-test/package.json +0ms
  corepack Checking /home/mike/github/package.json +0ms
  corepack Checking /home/mike/package.json +1ms
  corepack Checking /home/package.json +0ms
  corepack Checking /package.json +0ms
  corepack Falling back to [email protected]+sha224.c2e2e9ed3cdadd6ec250589b3393f71ae56d5ec297af11cec1eba3b4 as no project manifest were found +0ms
  corepack Installing [email protected] from https://repo.yarnpkg.com/4.5.2/packages/yarnpkg-cli/bin/yarn.js +4ms
  corepack Downloading to /home/mike/.cache/node/corepack/v1/corepack-6201-fa8f55d.d40be +1ms
! Corepack is about to download https://repo.yarnpkg.com/4.5.2/packages/yarnpkg-cli/bin/yarn.js
? Do you want to continue? [Y/n] n
/home/mike/n/lib/node_modules/corepack/dist/lib/corepack.cjs:21635
        throw new UsageError(`Aborted by the user`);
              ^

UsageError: Aborted by the user
    at fetchUrlStream (/home/mike/n/lib/node_modules/corepack/dist/lib/corepack.cjs:21635:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async download (/home/mike/n/lib/node_modules/corepack/dist/lib/corepack.cjs:21762:18)
    at async installVersion (/home/mike/n/lib/node_modules/corepack/dist/lib/corepack.cjs:21854:55)
    at async Engine.ensurePackageManager (/home/mike/n/lib/node_modules/corepack/dist/lib/corepack.cjs:22316:32)
    at async Engine.executePackageManagerRequest (/home/mike/n/lib/node_modules/corepack/dist/lib/corepack.cjs:22416:25)
    at async Object.runMain (/home/mike/n/lib/node_modules/corepack/dist/lib/corepack.cjs:23102:5) {
  clipanion: { type: 'usage' }
}

Node.js v23.6.0

Note: the documentation could be made clearer that corepack use creates a package.json if it does not exist. It only mentions that corepack use updates an existing package.json.

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

No branches or pull requests

1 participant