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 error code ENOENT npm error syscall spawn git npm error path git npm error errno -4058 npm error enoent An unknown git error occurred
How to fix "spawn git ENOENT" in npm
npm error code E401 npm error Incorrect or missing password.
How to fix 'E401 Unable to authenticate' errors with npm private registries
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm