How to deal with the yarn link "There's already a package called x registered" error
Note: tldr at the end of the article ;)
If you work on independent packages (or maybe even open-source npm modules - in which case I salute you!), you probably use the link functionality. And in that case, from time to time you will hit a really terrible warning message that looks like this:
This error (which is obscured as a warning, even though it stops the execution of the command) should be probably taught in programming schools as a great example of how NOT TO communicate errors to users. ;-)
The program should:
1 - verify whether the current registration matches the folder from which you ran the command - as this is frequently the case! Yarn should just inform the user the action had no effect because this has already been done. In other words - the developer should be able to just continue the work as planned. Maybe it should not even show a warning - unless while being in a debug mode, why should I care that the package I'm linking has already been linked? This message has 0 value to me in most cases, and it might disrupt my flow.
2 - in case the current registration actually does NOT match the folder from which you ran the command (rare case) - it should tell you from which folder the registration was done and give you an option to force the change.
Since that's not how it works, and the issue has been known for 2 years now ( https://github.com/yarnpkg/yarn/issues/7054 ) without any good arguments for keeping things as they are or plans to change it, here comes the solution and also tldr:
For lost googlers, this is another error you might see, the steps and reasoning stay the same:
Let me know if you have any questions or thoughts in the comments below.