The solution for a working npm/yarn link

Mattia Franchetto
Mar 5, 2018 · 2 min read

Every NodeJS developer comes to a point where a local package needs to be linked to an application to run some tests before publishing a new version on the registry. If you focus enough, you can hear developers from all around the world screaming after the most dangerous command has been run.


The problem is the way linking is done: npm/yarn use symbolic links to connect packages, duplicating dependencies that cannot be deduped since dedupe does not work for symlinks. This behaviour leads to an infinite number of problems, for example when only a version of a given package needs to be loaded for working properly, or when working with Typescript, where types packages loaded more than once cause tsc to fails in horrible and scary ways. Luckily for us a solution has been found!

You cannot be serious! I tried everything and nothing works!

It was a cloudy and dull afternoon when I ran into this Github issue.

The proposed change is really simple: instead of using symbolic links, just mimic what an actual publish might do. When you have made some changes to a module, pack all the files that npm will publish on the registry and instead of going public, put them on a local registry (a folder) and point the main package to it. Sounds complicated, right? Again, we are lucky because someone helped us with a simple CLI tool: say hello to yalc!

A simple scenario

cd moduleB
// do some changes
yalc publish // this will make the module available for other projects
cd moduleA
yalc add [module_B_name]

Building your project will result in a new version with the modified module B, same result as you would have run npm link, the only differences is that you won’t run into any troubles.

N.B. If the new version of B requires additional dependencies just remember to run npm/yarn install on your project.

Bonus tip

cd moduleB
// Do some changes
yalc push // the new version is published and pushed to all dependent projects

This is everything you need to get started with yalc, super simple but very effective. Please let me know if yalc worked for you too!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store