DEV Community

NPM Linking and Unlinking

Erin Bush on February 06, 2019

At work, we have our own npm packages that we manage and maintain. As part of the dev process its crucial to test out the package in the context of...
Collapse
 
peterwiebe profile image
Peter Wiebe •

Came across a similar linking issue and I wasn't able to fix it via unlinking, I had to resort to deleting the package-lock.json :(

Also, in case you weren't aware another way to npm link is to be in the directory of the project and then npm link ../../package-directory. I like it for saving me a step

Collapse
 
stephencweiss profile image
Stephen Charles Weiss •

Thanks Erin! This is exactly the situation I found myself in. Appreciate the write up!

Collapse
 
stephencweiss profile image
Stephen Charles Weiss •

Out of curiosity though -- why is the --no-save flag important?

Looks like unlink is an alias for uninstall, so the --no-save means uninstall, but don't remove from node_modules?

Collapse
 
erinbush profile image
Erin Bush •

Yep! If you don't include --no-save you'll end up removing that package from your package.json file. Of course, if you don't want to include the unlinked package in your package.json file, you can exclude the --no-save

Collapse
 
stephencweiss profile image
Stephen Charles Weiss •

Also... let's say you do goof and get the ENOENT: no such file or directory, access '/... error... then what?

Thread Thread
 
erinbush profile image
Erin Bush •

What I've had to do is go back to whatever state has the files/folders that npm is looking for. So let's say you have a package that is on one branch and not on another, you'd have to go back to your other branch and run npm link again for that package before running npm unlink my-package-name in your main project

Thread Thread
 
menocomp profile image
Mina Luke •

You may also go to the folder where the symbolic link library is installed and deleted the folder.

Collapse
 
johngellert profile image
John Gellert •

Hi Erin! Thanks for explaining this topic more.

What is npm install -g i . doing? I understand that it is installing the package globally with the -g and the . is taking all the files from the current directory. Specifically, what is i? Is this an alias? And why do you add it here?

Collapse
 
johngellert profile image
John Gellert •

Is the i referring to the NPM at this link npmjs.com/package/i

Is there a reason to install i along with the folder where package.json is located?

Collapse
 
jashgopani profile image
Jash Gopani •

Whenever I run npm unlink in my package folder, it removes a lot of global node modules...I am not able to understand what exactly is happening

Collapse
 
jimlynchcodes profile image
Jim Lynch •

Awesome post! I also dislike the fact that the --no-save option is needed. I ran npm unlink without it and now I can't use the original package anymore... 😢

Collapse
 
bigclown profile image
Alejandro Ariel Serra •

Hey Erin, i found this really helpfull. But i broke the pipeline by sending the push with the linked custom package. So i hope no one did that

Collapse
 
xargr profile image
greg 💻 •

if I delete link package how to delete symbolic link?