DEV Community

Vlatko Koudela
Vlatko Koudela

Posted on

How to fix "Received invalid response from npm" when using other registry in .npmrc and .yarnrc

Working on long term projects and keeping up with the technologies can be hard. It may happen that some of the technologies you're using change their configuration setting and you don't see their docs on time or you simply - forget. This happened to me while using the pro version of FontAwesome. Their license "authentication" has changed over time and that's fine if your project is young, but it's less obvious when working on long term project.

If you're reading this article, then you might be taken here by search engine that crawled this error:

error Received invalid response from npm.
Enter fullscreen mode Exit fullscreen mode

In my case, I got this error while trying to execute yarn info prop-types, but it can be any package from your packages.json file.

During the problem, yarn install doesn't work so you may end up with the similar looking error:

yarn install v1.19.2
[1/4] ๐Ÿ” Resolving packages...
[2/4] ๐Ÿšš Fetching packages...
error An unexpected error occurred: "https://npm.example.com/prop-types/-/prop-types-15.7.2.tgz: Request failed \"404 Not Found\"".
info If you think this is a bug, please open a bug report with the information provided in "/Users/vkoudela/path-to/your-project/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Enter fullscreen mode Exit fullscreen mode

When you encounter this or similar problem, many developers would say:

  1. Delete node_modules folder and then try yarn install
  2. Delete node_modules, yarn.lock and then try again
  3. Run yarn cache clean and then try again

But, what if you already tried that and it didn't help?

We, developers, when trying to fix something, we tend to run something and then we see what happens. We fix one problem, then another, until we fix all of them.

So, to be able to solve your problem, you have to know in which order yarn is using *rc files.

  1. In your project root (folder where you have your packages.json), it looks for .yarnrc file
  2. Then it looks for .npmrc
  3. Then it tries to find those files globally, which is usually your user folder: ~/.yarnrc
  4. Then it tries the same thing with ~/.npmrc

While troubleshooting and "fixing" the problem, you have to be aware of the fact that even if yarn install fails to execute properly, it would still create yarn.lock file taking all the settings from all .npmrc and .yarnrc on all four locations on your file system. So, even if you change any of the *rc files on any location after first failed attempt, it's not enough because settings are written in yarn.lock and yarn will reuse them on next execution.

Therefore, don't forget to delete yarn.lock before every other attempt of yarn install.

Top comments (0)