This error occurs when npm tries to create a symlink but a file or symlink already exists at that location. Usually from a previous npm link, conflicting packages, or broken symlinks.
The EEXIST error means npm is trying to create a symbolic link, but something already exists at the destination path. This commonly happens when: - You previously ran `npm link` and the symlink still exists - Two packages are trying to create the same executable (like two different versions of the same CLI tool) - A broken symlink from a deleted package is left behind npm won't overwrite existing files or symlinks automatically to prevent data loss, so you need to manually remove the conflicting file.
The error message shows the exact path. Note it down:
npm ERR! EEXIST: file already exists, symlink
npm ERR! /usr/local/bin/my-cli -> /usr/local/lib/node_modules/my-package/bin/cli.jsThe path before -> is where the conflict exists.
See if it's a file, symlink, or broken symlink:
# Check the file type
ls -la /usr/local/bin/my-cli
# If it's a symlink, see where it points
readlink /usr/local/bin/my-cli
# Check if the symlink target exists
ls -la $(readlink /usr/local/bin/my-cli)Once you've confirmed it's safe to remove:
# Remove the symlink or file
rm /usr/local/bin/my-cli
# Or if you need sudo
sudo rm /usr/local/bin/my-cliNow the operation should succeed:
# For npm link
npm link
# For global install
npm install -g my-packageIf you want npm to overwrite existing files:
npm install --force
npm link --forceWarning: This overwrites files without checking. Use only when you understand what will be overwritten.
Finding all linked packages: List globally linked packages to see what might conflict:
npm ls -g --depth=0
ls -la $(npm config get prefix)/lib/node_modulesDocker gotcha: Official Node.js Docker images include tools like Yarn pre-installed. If you try to install Yarn again, you'll get EEXIST. Either skip installing it or use --force.
Clean unlink workflow: Always unlink packages properly before removing them:
# In your project first
npm unlink my-package
# Then in the package directory
npm unlinknpm 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"