Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix this npm install conflict between existing files & symlinks?

I'm running into a problem with NPM, where it seems to be detecting a conflict between an existing file & a symlink, with the same name. I don't see any symlinks when running ls -l from my project's root folder. How do I figure out what's going on with NPM & straighten out this conflict?

The continuous integration build server is running: Node.js 4.4.3 = latest LTS build.

My localhost Node 5.x box switches to using phantomjs-prebuilt, due to this warning... so updating the Node server version from 4.4.3 -> 5.10.1 isn't the issue, nor the correct fix:

npm WARN deprecated [email protected]: Package renamed to phantomjs-prebuilt. Please update 'phantomjs' package references to 'phantomjs-prebuilt'

I don't have either of these in any of my *.js code, so I don't know where this is being required from nor why:

require("phantomjs") 
require("phantomjs-prebuilt")

Searching for this phrase on Google & SO, haven't produced enough useful results to solve my problem:

"npm ERR! EEXIST: file already exists, symlink"

Here is what I've already tried running:

npm uninstall -g phantomjs
npm WARN not installed in /.../.nvm/versions/node/v4/lib/node_modules: "phantomjs"

rm -rf node_modules // to delete that folder
npm install

npm ERR! EEXIST: file already exists, symlink '../phantomjs-prebuilt/bin/phantomjs' -> '/.../node_modules/.bin/phantomjs'
File exists: ../phantomjs-prebuilt/bin/phantomjs
Move it away, and try again.

A screenshot of what this error looks like was found on the web using Google. Scroll to the bottom of the CI server's code example. (Note: That is someone else's screenshot, but it looks similar to mine.)

Using npm list or npm ls shows phantomjs is installed:

├── [email protected]

Using npm ls -g shows a blank list. I assume that means that there aren't any packages, nor symlinks installed into a global area.

I've tried uninstalling phantomjs using:

npm uninstall -g phantomjs
npm WARN not installed in /.../.nvm/versions/node/v4/lib/node_modules: "phantomjs"

I've also tried using wilmore's idea from his answer at this Homebrew - repeated “linking” bug. What is the underlying issue here? question:

brew link --overwrite phantomjs
Warning: Already linked: /usr/local/homebrew/Cellar/phantomjs/2.1.1
To relink: brew unlink phantomjs && brew link phantomjs

That led me to choose the 1st option from that last line:

brew unlink phantomjs
Unlinking /usr/local/homebrew/Cellar/phantomjs/2.1.1... 2 symlinks removed

When I re-run:

npm install

It still trips over this error:

npm ERR! EEXIST: file already exists, symlink '../phantomjs-prebuilt/bin/phantomjs' -> '/.../node_modules/.bin/phantomjs'
File exists: ../phantomjs-prebuilt/bin/phantomjs
Move it away, and try again.

How do I debug symlinks further & fix this npm install conflict between existing files & symlinks?

like image 706
Clomp Avatar asked Apr 14 '16 21:04

Clomp


2 Answers

I just figured it out while after writing this question & attempting to recreate this issue, so that others could debug it. So here is how to fix this edge case error, in case anyone runs into it in the future.

I simply deleted both of these from my package.json file & then re-ran npm install to see what would happen. Then checking them into the CI server, I could see what it was doing. I had to re-add the first "phantomjs" line to get the CI server to pass it's tests. It was the "phantomjs-prebuilt" line, which had to be removed.

The comments explain which should be used with the 4.x & 5.x versions of Node.js:

"phantomjs": "^2.1.3", // Leave this in for Node 4.x LTS, remove it with 5.x+
"phantomjs-prebuilt": "^2.1.7", // Removed this with 4.x LTS, but use it with 5.x+

That's what fixed the CI server & allowed the tests to pass! :)

Originally, I had been using Node 5.6.0 (installed Feb 2016) & have been trying to update some Gulp tasks to work with the existing Node 4.4.3 LTS CI server.

Gulp kept complaining about phantomJS when using 5.6.0, so I had installed both phantomjs & phantomjs-prebuilt with --save-dev to get it to stop causing problems. Then downgrading from Node 5.6.0 to 4.4.3 LTS to debug the CI server, would throw out the symlinks error (mentioned in my question above).

So if anyone else runs into this npm ERR! EEXIST: issue in the future, try removing all references to the npm module - which the error talks about - from the package.json file. Then re-add them 1-by-1 if your CI server requires them.

The symlink would exist somewhere buried in the /node_modules/ folder. My /node_modules/ folder has 885 sub-folders! There was no way that I was going into all of them, to try to figure out what was wrong with the symlinks at some lower level.

However, if anyone has any good tips on how to debug symlinks, I'd love to know more about them. I would upvote good answers, because something easy to use like ls -l symlinks doesn't exist.

like image 178
Clomp Avatar answered Sep 24 '22 12:09

Clomp


In my case I was facing this problem when I was installing my org's package globally.

npm ERR! code EEXIST
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/@{orgname}/{packagename}/bin/index.js
npm ERR! dest /Users/user.name/.nvm/versions/node/v12.22.7/bin/{package_name}
npm ERR! errno -17
npm ERR! EEXIST: file already exists, symlink '../lib/node_modules/@{orgname}/{packagename}/bin/index.js' -> '/Users/user.name/.nvm/versions/node/v12.22.7/bin/packagename'
npm ERR! File exists: /Users/{user.name}/.nvm/versions/node/v12.22.7/bin/{packagename}
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

So as per npm's suggestion I installed the package with --force and it worked.

npm install -g @orgname/packagename --force

like image 31
was_777 Avatar answered Sep 21 '22 12:09

was_777