yarn install: Couldn't find package X on the 'npm' registry

avatar
Borislav Hadzhiev

Last updated: May 10, 2023
3 min

banner

# yarn install: Couldn't find package 'X' on the 'npm' registry

The yarn error "Couldn't find package 'X' on the 'npm' registry" occurs for multiple reasons:

  • Having a firewall or other network issues that prevent you from accessing the npm registry.
  • Having incorrect configuration properties in your ~/.yarnrc or ~/.npmrc file (e.g. the registry is set incorrectly).
  • Forgetting to log in with the npm login command before you install private packages.
  • Having a glitched node_modules folder or yarn.lock file.

To solve the error, set your registry correctly.

Here is the complete error message:

shell
error Couldn't find package "X" required by "Y" on the "npm" registry. info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. Error: Couldn't find package "X" required by "Y" on the "npm" registry.

# Try running the yarn command with the --verbose option

The first thing you should try is to run the yarn command with the --verbose options and look at the error message.

shell
# Installing all modules yarn install --verbose yarn --verbose # or installing a specific module yarn add axios --verbose

run yarn install in verbose mode

The --verbose option will print more information as to why the command failed.

# Try setting your registry correctly

Open your terminal and run the following command to set your registry correctly.

shell
yarn --registry https://registry.npmjs.org

set yarn registry correctly

You can also set your registry using npm.

shell
npm config set registry https://registry.npmjs.org

set npm registry correctly

Try to rerun the yarn installation command after making the change.

If the error persists, you can also try to temporarily rename your ~/.npmrc file and run your yarn installation command.

  1. Rename the ~/.npmrc and ~/.yarnrc files temporarily.
shell
mv ~/.npmrc ~/.npmrc2 mv ~/.yarnrc ~/.yarnrc2
  1. Run your yarn installation command.
shell
# install all modules yarn # install a specific module yarn add <YOUR_MODULE>
  1. Rename the configuration files back.
shell
mv ~/.npmrc2 ~/.npmrc mv ~/.yarnrc2 ~/.yarnrc

You can also try to use npm instead of yarn if that works for you.

shell
# installing all modules npm install # installing a specific module npm install <YOUR_MODULE>

If the issue persists, try to delete the registry property from your yarn and npm configs.

shell
# remove registry from yarn config yarn config delete registry # remove registry from npm config npm config delete registry

Try to run your installation command.

If the error persists, try to set the property using npm.

shell
npm cache clear --force npm config set registry https://registry.npmjs.org/

Try to run your installation command.

You can also try using the non-HTTPS version if that didn't work.

shell
npm config set registry http://registry.npmjs.org/

# Rerun the npm login command if installing private packages

If you are trying to install private packages that require you to be authorized, rerun the npm login command and enter your credentials again.

shell
npm login

You can also set the always-auth property to true in ~/.npmrc if you use a private NPM registry that always requires you to authenticate.

This should only be set if you use a private registry that requires authentication.

~/.npmrc
always-auth=true registry=YOUR_PRIVATE_NPM_REGISTRY

You can use nano or gedit to make the change.

shell
# with Gedit sudo gedit ~/.npmrc # or with Nano sudo nano ~/.npmrc

You can also try to clean the yarn cache.

shell
yarn cache clean

# Delete your node_modules and lock files and reinstall your dependencies

If the issue persists, try to delete your node_modules folder and your yarn.lock file and reinstall your dependencies.

If you are on macOS and Linux, open bash or zsh in your project's root directory and issue the following commands.

shell
# for macOS and Linux rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐Ÿ‘‡๏ธ clean the cache yarn cache clean npm cache clean --force # ๐Ÿ‘‡๏ธ install packages yarn install

If you are on Windows, run the following commands instead.

shell
# for Windows rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐Ÿ‘‡๏ธ clean the cache yarn cache clean npm cache clean --force # ๐Ÿ‘‡๏ธ install packages yarn install

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2025 Borislav Hadzhiev