Link NPM Dependencies from Local

Abhinav
1 min readJan 1, 2023

--

You have 2 different JS modules you’re working on, and one is dependent on the other.

Let’s call the first module user-management, and the others subscriptions, where subscriptions is dependent on user-management .

Typically, the package.json of subscriptions would have a dependency like this —

dependencies {
...
"@example/user-management" : "0.0.33"
}

Now you’re working on some changes in user-management , and you want to test how those changes affect subscriptions .

There are multiple ways of testing this — Linking a module to a github repo, publishing beta releases, or linking to a local module. In this blog, we’ll discuss the simplest approach — linking to a local module.

You can ask npm or yarn to link the modules locally by using the yarn link command.

work>cd user-management
user-management>yarn run build
user-management>yarn link
user-management>cd ../subscriptions
subscriptions>yarn link "@example/user-management"

That’s it. This will allow you to use whatever is in the dist folder of the user-management folder to be used as the dependency in subscriptions .

Unlinking is equally simple.

work>cd user-management
user-management>yarn unlink
user-management>cd ../subscriptions
subscriptions>yarn unlink "@example/user-management"

That’s all.

--

--