Allow `corepack use` with default package manager when network disabled `COREPACK_ENABLE_NETWORK=0`
What would you like?
corepack use should default to the package manager version stored in lastKnownGood.json when network connections are disabled with COREPACK_ENABLE_NETWORK=0.
For example
corepack use yarn
should work if previously Yarn was globally installed:
corepack install -g yarn@<specific-version>
Why is this needed?
Version-independent workflows including for example corepack use yarn should still work with no network available.
Steps to reproduce
Ubuntu 22.04.2 LTS, Node.js 22.14.0 LTS, Corepack 0.32.0
rm -rf ~/.cache/node/corepack
corepack install -g [email protected]
export COREPACK_ENABLE_NETWORK=0
cd $(mktemp -d)
corepack use yarn # fails
corepack use [email protected] # succeeds
Logs
Failure
$ corepack use yarn # fails
Usage Error: Network access disabled by the environment; can't reach npm repository https://registry.npmjs.org
$ corepack use <pattern>
Success
$ corepack use [email protected] # succeeds
Installing [email protected] in the project...
➤ YN0000: · Yarn 4.8.0
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done in 0s 78ms
It seems that COREPACK_DEFAULT_TO_LATEST is not working as it should be because the following also does not work
rm -rf ~/.cache/node/corepack
corepack install -g [email protected]
export COREPACK_ENABLE_NETWORK=0
export COREPACK_DEFAULT_TO_LATEST=0
corepack use npm@6
@yeikel
It seems that
COREPACK_DEFAULT_TO_LATESTis not working as it should be because the following also does not workrm -rf ~/.cache/node/corepack corepack install -g [email protected] export COREPACK_ENABLE_NETWORK=0 export COREPACK_DEFAULT_TO_LATEST=0 corepack use npm@6
Please post this as a separate new issue if you believe it is a bug. Given that your last instruction using npm@6 specifies a partial version, I don't know how this could work without access to the registry, so possibly this could be added to the documentation as a restriction. Whatever the assessment is about your problem description, it is a separate topic in any case.
I would also suggest that you first describe the situation where you only set COREPACK_DEFAULT_TO_LATEST=0 without setting COREPACK_ENABLE_NETWORK=0, including how it currently works, and how you expected it to work.