How to fix npm ERR! code EEXIST npm ERR! EEXIST: file already exists, symlink in npm
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.
Quick fix
Fixes npm ERR! code EEXIST npm ERR! EEXIST: file already exists, symlink
npm ERR! EEXIST: file already exists, symlink
npm ERR! /usr/local/bin/my-cli -> /usr/local/lib/node_modules/my-package/bin/cli.js- Identify the conflicting file
- Check what's at that path
- Remove the conflicting file or symlink
- Retry the npm operation
npm ERR! EEXIST: file already exists, symlinknpm ERR! /usr/local/bin/my-cli -> /usr/local/lib/node_modules/my-package/bin/cli.jsnpm ERR! code EEXISTnpm ERR! EEXIST: file already exists, symlink
What this error means
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.
Typical symptoms
- npm link fails with 'EEXIST: file already exists'
- npm install -g fails for a package you had linked before
- Error shows the exact path where the conflict exists
- Multiple packages providing the same CLI command
Common causes
- Previous npm link created a symlink that still exists
- Broken/orphaned symlink from deleted package
- Two packages trying to create same executable name
- Interrupted npm operation left partial files
- Manual file created at symlink destination
How to fix "npm ERR! code EEXIST npm ERR! EEXIST: file already exists, symlink"
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.
Advanced notes
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 unlinkFrequently asked questions
- What does "npm ERR! code EEXIST npm ERR! EEXIST: file already exists, symlink" mean?
- 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.
- How do I fix "npm ERR! code EEXIST npm ERR! EEXIST: file already exists, symlink"?
- 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.
- What causes "npm ERR! code EEXIST npm ERR! EEXIST: file already exists, symlink"?
- Previous npm link created a symlink that still exists Broken/orphaned symlink from deleted package Two packages trying to create same executable name
- Is the "npm ERR! code EEXIST npm ERR! EEXIST: file already exists, symlink" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐ฌSO: npm install symlink conflicts(Stack Overflow)
- ๐GitHub: npm issues(GitHub)
- ๐Docs: npm install(Official Docs)