2021-07-13
|~1 min read
|197 words
I’ve written in the past about how to link packages with NPM (and yarn’s pack
too), but sometimes, what you need to know is not how to link something, but whether or not you’ve already done it. I find that when I’m developing libraries, knowing whether or not I’ve previously linked a package is incredibly useful - particularly for debugging bugs.
There are a number of different ways to find this information (here’s a StackOverflow that discusses multiple approaches), but the most straightforward one I’ve found is with npm
’s CLI:
% npm ls --depth=0 --link=true
my-project@1.85.0 /Users/stephen.weiss/code/my-project
└── @linked-library@0.4.65 -> /Users/stephen.weiss/code/linked-library
If you no longer want this link, you can use the unlink
command and then reinstall the dependencies. With yarn
this looks like (for npm
I wrote about it here):
% yarn unlink "linked-library"
yarn unlink v1.22.4
success Removed linked package "linked-library".
info You will need to run `yarn install --force` to re-install the package that was linked.
Hopefully this helps save some time in the future when you’re trying to figure out why your application is behaving peculiarly! I know it’s helped me a dozen times already.
Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!