share
Stack Overflow"corepack prepare yarn@3.4.1 --activate" results in "Internal Error: Server answered with HTTP 503"
[+2] [1] crs1138
[2023-06-07 16:41:11]
[ node.js yarnpkg-v2 ]
[ https://stackoverflow.com/questions/76425465/corepack-prepare-yarn3-4-1-activate-results-in-internal-error-server-answ ]

I'm using this with Jenkins.

  1. I set up Node to the version (v16.15.1) set in .nvmrc file:
if (fileExists('.nvmrc')) {
  sh 'bash -l -c "(((nvm install > /dev/null) && nvm use) && nvm alias default node) || true"'
}
  1. Then check if corepack is available and if not install it; then enable corepack and try to install yarn@3.4.1 (the same version is specified in package.json as the "packageManager": "yarn@3.4.1" property
sh "bash -l -c '(corepack --version || npm i -g corepack) && corepack enable && corepack prepare yarn@3.4.1 --activate'"

However, the last step (corepack prepare yarn@3.4.1 --activate) fails producing the following error message:

16:14:42  Internal Error: Server answered with HTTP 503
16:14:42      at ClientRequest.<anonymous> (/usr/local/nvm/versions/node/v16.15.1/lib/node_modules/corepack/dist/corepack.js:3933:31)
16:14:42      at Object.onceWrapper (node:events:642:26)
16:14:42      at ClientRequest.emit (node:events:527:28)
16:14:42      at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:631:27)
16:14:42      at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
16:14:42      at TLSSocket.socketOnData (node:_http_client:494:22)
16:14:42      at TLSSocket.emit (node:events:527:28)
16:14:42      at addChunk (node:internal/streams/readable:315:12)
16:14:42      at readableAddChunk (node:internal/streams/readable:289:9)
16:14:42      at TLSSocket.Readable.push (node:internal/streams/readable:228:10)

I ran the command individually, so I can confirm that it is the last one that produces the error.

Please, help.

[0] [2023-06-30 08:56:52] muya_

After experiencing this error on Gitlab, switching up the runners helped resolve it.

Based on the discussion here [1], it seems the root cause might be some block-listing of IPs by Cloudflare.

Changing the source of the requests seems to have helped resolve the issue.

[1] https://github.com/yarnpkg/berry/discussions/5072

1