How to Link correctly in YARN

date
Feb 7, 2023
slug
link-correctly-in-yarn
status
Published
tags
yarn
summary
A summary of how to link your local packages via yarn
type
Post
So, if you ever work on a package distribution, you might sometimes want to verify a few things in the local before making an unwanted commit. So, below is a crux of how to do it properly with yarn
 
Lets assume you have a package pkg which you want to test it in a local repo called app . Though, you can mostly accomplish this via link, but link wont update on every change and its too complicated, i feel sometimes.
 
You can follow the below steps to test correctly:
  1. Get into the pkg and get the absolute path by typing pwd on mac (cd on windows). Copy it
  1. Go to the app package.json and add it as a dependency as below
dependencies: {
...
'pkg':"link:<absolute_path"
}
  1. And then run yarn in the app and you can start testing.
  1. For every change on the pkg
    1. You can remove node modules and reinstall
    2. or bump version of pkg and use yarn upgrade pkg --latest
This setup has enabled me to test faster than with yarn link and find-out why its not working as expected sometimes.
-Thank you 🙌🏻

Older Version 📦

⚠️ Still in beta. Report 🐞's here