npm - 如何解决现有文件和符号链接(symbolic link)之间的 npm install 冲突?

标签 npm continuous-integration devops

我遇到了 NPM 的问题,它似乎正在检测现有文件和符号链接(symbolic link)之间的冲突,具有相同的名称。
运行 ls -l 时看不到任何符号链接(symbolic link)从我项目的根文件夹中。我如何弄清楚 NPM 发生了什么并解决这个冲突?

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

由于这个警告,我的 localhost Node 5.x 框切换到使用 phantomjs-prebuilt ......所以从 4.4.3 -> 5.10.1 更新 Node 服务器版本不是问题,也不是正确的修复:

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显示一个空白列表。我认为这意味着没有任何软件包,也没有安装到全局区域的符号链接(symbolic link)。

我尝试使用以下方法卸载 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.

如何进一步调试符号链接(symbolic link)并修复此问题 npm install现有文件和符号链接(symbolic link)之间的冲突?

最佳答案

我只是在写完这个问题并尝试重新创建这个问题之后才弄清楚,以便其他人可以调试它。所以这里是如何解决这个极端情况错误,以防将来有人遇到它。

我只是从我的 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让它停止引起问题。然后从 Node 5.6.0 降级到 4.4.3 LTS 以调试 CI 服务器,会抛出符号链接(symbolic link)错误(在我上面的问题中提到)。

因此,如果其他人遇到此 npm ERR! EEXIST:将来出现问题,请尝试从 package.json 文件中删除对 npm 模块的所有引用(错误所涉及的内容)。如果您的 CI 服务器需要它们,然后重新添加它们 1-by-1。

符号链接(symbolic link)将存在于/node_modules/文件夹中的某个地方。我的/node_modules/文件夹有 885 个子文件夹!我无法深入研究所有这些,试图找出较低级别的符号链接(symbolic link)有什么问题。

但是,如果有人对如何调试符号链接(symbolic link)有任何好的提示,我很想了解更多关于它们的信息。我会赞成好的答案,因为像 ls -l symlinks 这样易于使用的东西不存在。

关于npm - 如何解决现有文件和符号链接(symbolic link)之间的 npm install 冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36634657/

相关文章:

javascript - Node.js 'require' 不需要命名空间即可访问其他文件

asp.net-core - 为什么我的 Azure Pipeline 作业失败并显示错误 NU1101?

azure - 如何在 Azure Devops 中以正确的方式进行基于功能的部署?

java - 如何使用 docker 构建 J2EE 应用程序

laravel - 在 laravel mix 中需要一个 npm 包吗?

javascript - Typescript 中的外部 JavaScript 依赖项

continuous-integration - SonarQube - 如何将最后一次成功的分析指定为泄漏期

git - 以确保干净/正确的工作树和子模块的方式更改分支 (Git)

c# - Azure DevOps API 与语言无关吗?

javascript - 如何使用 npm 库中的 web-worker 到主 webpack 项目中