Last updated: Apr 5, 2024
Reading time·4 min
The yarn issue "There appears to be trouble with your network connection. Retrying..." occurs when your internet connection is too slow to install the specified package.
To solve the error, set the --network-timeout
flag to increase the timeout
when running the yarn add
command.
yarn add <YOUR_PACKAGE> --network-timeout 300000
Make sure to replace the <YOUR_PACKAGE>
placeholder with the actual name of
the package you're trying to install.
--network-timeout
flag can be used to set the timeout of the installation command to N milliseconds.If your command times out when installing all modules in your project, simply
set the --network-timeout
flag without specifying the name of a package.
yarn --network-timeout 300000
You can also set the network-timeout
flag globally for all yarn
commands so
you don't have to remember to set it every time.
yarn config set network-timeout 500000 -g
The next time you run the yarn
command to install your modules or yarn add
to install a specific module, the network-timeout
flag will be set to 500
seconds.
Increasing the timeout is often necessary when installing large packages or when your network connection is too slow.
If the issue persists, try to delete your node_modules
folder and yarn.lock
file and reinstall your dependencies.
If you are on Windows, run the following commands in CMD (Command Prompt).
# Windows rd /s /q "node_modules" del -f yarn.lock del package-lock.json # 👇️ clean your yarn cache yarn cache clean yarn
If you are on macOS or Linux, run the following commands in bash
or zsh
.
# macOS and Linux rm -rf node_modules rm -f yarn.lock rm -f package-lock.json # 👇️ clean your yarn cache yarn cache clean yarn
Deleting your yarn.lock
file and reinstalling your dependencies often resolves
the issue.
If you are trying to install a package from behind a proxy, make sure it is configured correctly.
For example, if you want to remove the proxy, run the following commands.
npm config rm http-proxy npm config rm https-proxy yarn config delete proxy yarn config delete https-proxy
Try to run your yarn
installation command after removing the proxy setting.
# Installing a specific package yarn add <YOUR_PACKAGE> --network-timeout 300000 # Installing all packages yarn --network-timeout 300000
If you instead want to set a proxy, run the following commands.
yarn config set proxy http://your_proxy_url:port yarn config set https-proxy https://proxy.company:8080
If you need to specify your credentials (username and password), use the following commands instead.
yarn config set proxy http://USERNAME:PASSWORD@your_proxy_url:port yarn config set https-proxy https://USERNAME:PASSWORD@proxy.company:8080
You can use the following command to verify that your proxy settings are set correctly.
yarn config get proxy yarn config get https-proxy
If you are on Windows and the issue persists, try to turn off real-time protection temporarily:
🪟
.Try to run your yarn
installation command after disabling real-time
protection.
# Installing a specific package yarn add <YOUR_PACKAGE> --network-timeout 300000 # installing all packages yarn --network-timeout 300000
If the issue persists, check out the following article:
You might have set the http_proxy
or https_proxy
environment variables.
You can unset them by following the steps in this subheading.
On macOS and Linux, you can use the following commands to unset the environment variables.
# on macOS and Linux unset http_proxy unset https_proxy unset HTTP_PROXY unset HTTPS_PROXY
On Windows, in CMD, use the following commands instead.
# on Windows (CMD) set http_proxy=null set https_proxy=null set HTTP_PROXY=null set HTTPS_PROXY=null
You can also try to set your NPM registry to npmjs.org
.
npm config set registry http://registry.npmjs.org/
Try to run your yarn
installation command after making the change.
# Installing a specific package yarn add <YOUR_PACKAGE> --network-timeout 300000 # Installing all packages yarn --network-timeout 300000
If that didn't work, try to set your NPM registry using HTTPS.
npm config set registry https://registry.npmjs.org/
Try to rerun your yarn
installation command after.
# Installing a specific package yarn add <YOUR_PACKAGE> --network-timeout 300000 # Installing all packages yarn --network-timeout 300000
If the issue persists, try to install the long-term supported version of Node.js by following the instructions in this subheading.
You can learn more about the related topics by checking out the following tutorials: