Last updated: May 10, 2023
Reading timeยท3 min

The yarn error "Couldn't find package 'X' on the 'npm' registry" occurs for multiple reasons:
npm registry.~/.yarnrc or ~/.npmrc
file (e.g. the registry is set incorrectly).npm login command before you install private
packages.node_modules folder or yarn.lock file.To solve the error, set your registry correctly.
Here is the complete error message:
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.
yarn command with the --verbose optionThe first thing you should try is to run the yarn command with the --verbose
options and look at the error message.
# Installing all modules yarn install --verbose yarn --verbose # or installing a specific module yarn add axios --verbose

The --verbose option will print more information as to why the command failed.
Open your terminal and run the following command to set your registry correctly.
yarn --registry https://registry.npmjs.org

You can also set your registry using npm.
npm config set registry https://registry.npmjs.org

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.
~/.npmrc and ~/.yarnrc files temporarily.mv ~/.npmrc ~/.npmrc2 mv ~/.yarnrc ~/.yarnrc2
yarn installation command.# install all modules yarn # install a specific module yarn add <YOUR_MODULE>
mv ~/.npmrc2 ~/.npmrc mv ~/.yarnrc2 ~/.yarnrc
You can also try to use npm instead of yarn if that works for you.
# 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.
# 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.
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.
npm config set registry http://registry.npmjs.org/
npm login command if installing private packagesIf you are trying to install private packages that require you to be authorized,
rerun the npm login command and enter your credentials again.
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.
always-auth=true registry=YOUR_PRIVATE_NPM_REGISTRY
You can use nano or gedit to make the change.
# with Gedit sudo gedit ~/.npmrc # or with Nano sudo nano ~/.npmrc
You can also try to clean the yarn cache.
yarn cache clean
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.
# 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.
# 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
You can learn more about the related topics by checking out the following tutorials: