Resolving Network Connection Error In Yarn

Rajat Saxena

July 9, 2023

So today, I was setting up a new monorepo project and I ran into the following error while setting the Yarn version to berry.

rajat@Rajats-MacBook-Air yarn-berry % yarn set version berry
info There appears to be trouble with your network connection. Retrying...

Upon some digging around, I discovered that Yarn was unable to reach Github.com as seen in the following trace.

rajat@Rajats-MacBook-Air yarn-berry % yarn set version berry --network-timeout 10000000 --verbose
verbose 0.088904291 Checking for configuration file "/Users/rajat/dev/throw-away/yarn-berry/.npmrc".
verbose 0.089522125 Checking for configuration file "/Users/rajat/.npmrc".
verbose 0.089589916 Found configuration file "/Users/rajat/.npmrc".
verbose 0.089890333 Checking for configuration file "/Users/rajat/.nvm/versions/node/v18.2.0/etc/npmrc".
verbose 0.089955208 Checking for configuration file "/Users/rajat/dev/throw-away/yarn-berry/.npmrc".
verbose 0.090007041 Checking for configuration file "/Users/rajat/dev/throw-away/.npmrc".
verbose 0.090125666 Checking for configuration file "/Users/rajat/dev/.npmrc".
verbose 0.0901665 Checking for configuration file "/Users/rajat/.npmrc".
verbose 0.090290833 Found configuration file "/Users/rajat/.npmrc".
verbose 0.090437375 Checking for configuration file "/Users/.npmrc".
verbose 0.091147083 Checking for configuration file "/Users/rajat/dev/throw-away/yarn-berry/.yarnrc".
verbose 0.091224125 Checking for configuration file "/Users/rajat/.yarnrc".
verbose 0.091271625 Found configuration file "/Users/rajat/.yarnrc".
verbose 0.09142775 Checking for configuration file "/Users/rajat/.nvm/versions/node/v18.2.0/etc/yarnrc".
verbose 0.091464458 Checking for configuration file "/Users/rajat/dev/throw-away/yarn-berry/.yarnrc".
verbose 0.091497208 Checking for configuration file "/Users/rajat/dev/throw-away/.yarnrc".
verbose 0.091585875 Checking for configuration file "/Users/rajat/dev/.yarnrc".
verbose 0.091625208 Checking for configuration file "/Users/rajat/.yarnrc".
verbose 0.091660708 Found configuration file "/Users/rajat/.yarnrc".
verbose 0.091760625 Checking for configuration file "/Users/.yarnrc".
verbose 0.092885916 current time: 2022-12-10T08:45:51.427Z
verbose 0.099392166 Performing "GET" request to "https://github.com/yarnpkg/berry/raw/master/packages/yarnpkg-cli/bin/yarn.js".
info There appears to be trouble with your network connection. Retrying...

Turns out, I needed to enable corepack for it to work as listed in the Yarn's official migration guide. My Node version was 18.

corepack enable

After the above command, I was able to set the Yarn version properly. Hope it was helpful

Become 1% better, every week

We send you the latest news, articles, and tutorials about full stack development every week. Drop your email to start skilling up and stay ahead in the game!