This error occurs when npm tries to remove a symlink that doesn't exist. Usually because the package was already unlinked, manually deleted, or you're in the wrong directory.
The ENOENT error during `npm unlink` means npm is looking for a symbolic link to remove, but it doesn't exist. This happens when: - The package was already unlinked previously - The symlink was manually deleted - You switched Node versions (with nvm) and the symlink is in a different global directory - The original package directory was moved or deleted - You're running unlink in the wrong directory The error is usually harmless—the symlink is already gone. But if you're trying to clean up a broken link setup, you may need to manually verify and fix the state.
Verify the current link state:
# List globally linked packages
npm ls -g --depth=0
# Check if symlink exists
ls -la $(npm config get prefix)/lib/node_modules/ | grep my-packageIf the package doesn't appear, it's already unlinked.
For unlinking, you need to be in the correct location:
# To unlink from your project (removes the local symlink)
cd /path/to/my-project
npm unlink my-package
# To unlink the global link (removes from global node_modules)
cd /path/to/original-package
npm unlinkThe error often occurs when you're in the wrong directory.
If using nvm, check which Node version created the link:
# See current Node version
node --version
# List all Node versions
nvm ls
# Each version has its own global node_modules
ls ~/.nvm/versions/node/v*/lib/node_modulesYou may need to switch to the Node version that was used when linking.
If the state is inconsistent, re-establish the link first:
# Go to the package directory
cd /path/to/my-package
# Create the global link
npm link
# Go to your project
cd /path/to/my-project
# Link in project
npm link my-package
# Now unlink should work
npm unlink my-packageIf automatic unlink doesn't work, manually remove:
# Remove from global node_modules
rm $(npm config get prefix)/lib/node_modules/my-package
# Remove the binary symlink if it exists
rm $(npm config get prefix)/bin/my-package
# Clean up your project
cd /path/to/my-project
rm -rf node_modules
npm installOrder matters: When unlinking, always unlink from your project first, then unlink globally:
cd /path/to/project && npm unlink my-package # First: from project
cd /path/to/package && npm unlink # Second: global linkUse --no-save to preserve package.json: If you want to unlink but keep the dependency in package.json:
npm unlink my-package --no-saveGit branch switching: If you linked a package and then switched to a Git branch where that package doesn't exist, unlink will fail. Switch back to the original branch first.
Safe to ignore: If the error occurs because the link is already gone, you can safely ignore it. The unlink was essentially already done.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"