yarn unlink: must yarn unlink [package] before yarn unlink despite message to the contrary
https://yarnpkg.com/en/docs/cli/unlink
The example given on that page, and the message output by yarn unlink, strongly implies you run yarn unlink and then yarn unlink [package]. But it fails:
$ cd my-package
$ yarn unlink
yarn unlink v1.3.2
success Unregistered "my-package".
info You can now run `yarn unlink "my-package"` in the projects where you no longer want to use this module.
✨ Done in 0.09s.
$ cd ../my-package-user
$ yarn unlink my-package
yarn unlink v1.3.2
error No registered module found called "my-package".
info Visit https://yarnpkg.com/en/docs/cli/unlink for documentation about this command.
To make it work, unlink in the reverse order to linking: yarn unlink my-package then yarn unlink.
What would be a clearer text?
My suggestions:
- Fix the
yarn unlinkcode so it doesn't tell people to do something that doesn't work. - In the first paragraph of the
yarn unlinkdoc page, say explicitly that you should use the twoyarn unlinkcommands in the reverse order to theyarn linkcommands. - Fix the code samples on the page so the two flavours of
yarn unlinkare run in the correct order, and show what yarn actually outputs in each case.
I would also look at the terminology for this page and yarn link. For someone unfamiliar with the commands (the target audience for this page) it's easy to become confused between the two packages: "The package you want to link" and "current project" are pretty vague/ambiguous terms. "Package" and "project" are fundamentally synonymous (for example, see https://yarnpkg.com/en/docs/cli/, which saysyarn add "adds a package to use in your current package"). "Source" and "target" would be similarly ambiguous (it all depends on perspective).
The main use case is: I'm modifying a dependency of a package and want to try it out inside that package without having to publish it. So perhaps the doc should use the term "dependency" and whatever is a good, unambiguous yarn/npm way to say "a package that depends on that dependency"... "consuming package"?
For anyone who lands here with this problem after running the yarn unlink in the source package directory command first. To recover from this situation, you can rerun, yarn link in the source package directory, then do the yarn unlink <source-package> commands in the correct order and then finish with the final yarn unlink in the source package directory.
I'm surprised this isn't fixed, I keep running into this when developing packages.
Btw, this is how you find your links:
For anyone else coming here, you can delete the link in ~/.config/yarn/link
https://github.com/yarnpkg/yarn/issues/7054#issuecomment-465817796
I cried, the linked package name is the same, but it is actually in a different project, various errors.
Yarn unlink package name yarn unlink then yarn link solved the problem
Yarn global setting is a problem
Lost my week of youth :)