This post goes over how to link and unlink npm packages.
Prerequisites
Assuming you have 2 packages:
pkg-a
pkg-b
npm link
Go to your package directory that contains package.json
:
cd path/to/pkg-a
Create a global symlink:
npm link
Verify that the global link is created:
npm ls --global --depth=0
You should see something like:
/Users/remarkablemark/.nvm/versions/node/v18.18.1/lib
├── [email protected] -> ./../../../../../pkg-a
└── [email protected]
npm link
Go to another package directory:
cd path/to/pkg-b
Link install package pkg-a
:
npm link pkg-a
Verify the package is installed:
npm ls pkg-a
You should see something like:
pkg-b@ /path/to/pkg-b
└── [email protected] -> ./../pkg-a
npm unlink
Given you’re still in package pkg-b
directory:
cd path/to/pkg-b
Unlink package pkg-a
:
npm unlink pkg-a
Go to package pkg-a
directory:
cd path/to/pkg-a
Unlink the package globally:
npm unlink --global
Verify the global package is unlinked:
npm ls -g pkg-a
You should see the following:
/Users/remarkablemark/.nvm/versions/node/v18.18.1/lib
└── (empty)