如何解决现有文件和现有文件之间的这种npm安装冲突?符号链接?

时间:2016-04-14 21:52:27

标签: npm continuous-integration devops

我遇到NPM的问题,它似乎检测到现有文件与现有文件之间的冲突。符号链接,名称相同。 从项目的根文件夹运行ls -l时,我没有看到任何符号链接。我如何弄清楚NPM&amp ;?正在发生什么?理顺这场冲突?

持续集成构建服务器正在运行:Node.js 4.4.3 =最新的LTS构建。

由于此警告,我的localhost节点5.x框切换到使用phantomjs-prebuilt ...因此更新4.4.3中的节点服务器版本 - > 5.10.1不是问题,也不是正确的解决方法:

npm WARN deprecated phantomjs@2.1.7: Package renamed to phantomjs-prebuilt. Please update 'phantomjs' package references to 'phantomjs-prebuilt'

我的* .js代码中没有其中任何一个,所以我不知道这是从哪里来的,也不知道为什么:

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

Google&上搜索此短语SO,尚未产生足够有用的结果来解决我的问题:

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

以下是我已尝试过的内容:

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.

使用Google在网络上找到了此错误的截图。滚动到CI server's code example的底部。 (注意:这是其他人的屏幕截图,但它看起来与我的相似。)

使用npm listnpm ls显示已安装phantomjs:

├── phantomjs@2.1.7

使用npm ls -g显示空白列表。我认为这意味着没有任何软件包,也没有安装到全球区域的符号链接。

我尝试使用以下方法卸载phantomjs:

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

我也尝试在wilmore问题的答案中使用Homebrew - repeated “linking” bug. What is the underlying issue here?的答案:

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

这导致我从最后一行中选择第一个选项:

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

当我重新跑步时:

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.

如何进一步调试符号链接&修复现有文件与现有文件之间的npm install冲突符号链接?

1 个答案:

答案 0 :(得分:3)

在写完这个问题之后,我才想到了这个问题。尝试重新创建此问题,以便其他人可以调试它。所以这里是如何解决这个边缘情况错误,以防将来有人遇到它。

我只是从package.json文件中删除了这两个文件。然后重新跑npm install看看会发生什么。然后检查它们到CI服务器,我可以看到它在做什么。我不得不重新添加第一个" phantomjs"行让CI服务器通过它的测试。这是" phantomjs-prebuilt"线,必须删除。

评论说明哪些应与4.x& 5.x版本的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+

是什么修复了CI服务器&允许测试通过! :)

最初,我一直在使用Node 5.6.0(2016年2月安装)&一直在尝试更新一些Gulp任务以使用现有的Node 4.4.3 LTS CI服务器。

Gulp在使用5.6.0时一直抱怨phantomJS,所以我安装了phantomjs& phantomjs-prebuilt--save-dev npm ERR! EEXIST:让它停止造成问题。然后从节点5.6.0降级到4.4.3 LTS以调试CI服务器,会抛出符号链接错误(在我上面的问题中提到)。

因此,如果将来有其他人遇到此ls -l symlinks问题,请尝试从package.json文件中删除对npm模块的所有引用(错误所述)。然后,如果CI服务器需要,请逐个重新添加它们。

符号链接将存在于/ node_modules /文件夹中的某处。我的/ node_modules /文件夹有885个子文件夹!我无法进入所有这些,试图弄清楚某些较低级别的符号链接有什么问题。

但是,如果有人对如何调试符号链接有任何好的提示,我很想知道更多关于它们的信息。我会提出好的答案,因为像i这样易于使用的东西并不存在。

相关问题