【Ambari编译报错】phantomjs从github上下载失败导致无法编译的问题

PhantomJS 下载失败问题

1. 错误分析

下面是完整的报错日志:

[ERROR] npm verb unsafe-perm in lifecycle true
[ERROR] npm verb unlock done using /root/.npm/_locks/phantomjs-ca2567298810d09d.lock for /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/phantomjs
[ERROR] npm verb unlock done using /root/.npm/_locks/core-js-29b3f75c7b038ece.lock for /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/karma/node_modules/core-js
[ERROR] npm verb about to build /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/karma
[ERROR] npm info build /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/karma
[ERROR] npm info linkStuff karma@2.0.5
[ERROR] npm verb linkBins karma@2.0.5
[ERROR] npm verb link bins [ { karma: './bin/karma' },
[ERROR] npm verb link bins   '/opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/.bin',
[ERROR] npm verb link bins   false ]
[ERROR] npm verb linkMans karma@2.0.5
[ERROR] npm verb rebuildBundles karma@2.0.5
[ERROR] npm verb gentlyRm don't care about contents; nuking /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/.bin/karma
[ERROR] npm verb rebuildBundles [ '.bin',
[ERROR] npm verb rebuildBundles   'bluebird',
[ERROR] npm verb rebuildBundles   'body-parser',
[ERROR] npm verb rebuildBundles   'chokidar',
[ERROR] npm verb rebuildBundles   'colors',
[ERROR] npm verb rebuildBundles   'combine-lists',
[ERROR] npm verb rebuildBundles   'connect',
[ERROR] npm verb rebuildBundles   'core-js',
[ERROR] npm verb rebuildBundles   'di',
[ERROR] npm verb rebuildBundles   'dom-serialize',
[ERROR] npm verb rebuildBundles   'expand-braces',
[ERROR] npm verb rebuildBundles   'glob',
[ERROR] npm verb rebuildBundles   'graceful-fs',
[ERROR] npm verb rebuildBundles   'http-proxy',
[ERROR] npm verb rebuildBundles   'isbinaryfile',
[ERROR] npm verb rebuildBundles   'lodash',
[ERROR] npm verb rebuildBundles   'log4js',
[ERROR] npm verb rebuildBundles   'mime',
[ERROR] npm verb rebuildBundles   'minimatch',
[ERROR] npm verb rebuildBundles   'optimist',
[ERROR] npm verb rebuildBundles   'qjobs',
[ERROR] npm verb rebuildBundles   'range-parser',
[ERROR] npm verb rebuildBundles   'rimraf',
[ERROR] npm verb rebuildBundles   'safe-buffer',
[ERROR] npm verb rebuildBundles   'socket.io',
[ERROR] npm verb rebuildBundles   'source-map',
[ERROR] npm verb rebuildBundles   'tmp',
[ERROR] npm verb rebuildBundles   'useragent' ]
[ERROR] npm info install karma@2.0.5
[ERROR] npm info postinstall karma@2.0.5
[ERROR] npm verb unlock done using /root/.npm/_locks/karma-f241847ca8dea731.lock for /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/karma
[ERROR] npm verb stack Error: phantomjs-prebuilt@2.1.16 install: `node install.js`
[ERROR] npm verb stack Exit status 1
[ERROR] npm verb stack     at EventEmitter.<anonymous> (/opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node/node_modules/npm/lib/utils/lifecycle.js:217:16)
[ERROR] npm verb stack     at emitTwo (events.js:87:13)
[ERROR] npm verb stack     at EventEmitter.emit (events.js:172:7)
[ERROR] npm verb stack     at ChildProcess.<anonymous> (/opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node/node_modules/npm/lib/utils/spawn.js:24:14)
[ERROR] npm verb stack     at emitTwo (events.js:87:13)
[ERROR] npm verb stack     at ChildProcess.emit (events.js:172:7)
[ERROR] npm verb stack     at maybeClose (internal/child_process.js:829:16)
[ERROR] npm verb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
[ERROR] npm verb pkgid phantomjs-prebuilt@2.1.16
[ERROR] npm verb cwd /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web
[ERROR] npm ERR! Linux 5.15.153.1-microsoft-standard-WSL2
[ERROR] npm ERR! argv "/opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node/node" "/opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node/node_modules/npm/bin/npm-cli.js" "in
stall" "--unsafe-perm" "--progress" "--save" "--verbose" "--registry=https://registry.npmmirror.com/"
[ERROR] npm ERR! node v4.5.0
[ERROR] npm ERR! npm  v2.15.0
[ERROR] npm ERR! code ELIFECYCLE
[ERROR]
[ERROR] npm ERR! phantomjs-prebuilt@2.1.16 install: `node install.js`
[ERROR] npm ERR! Exit status 1
[ERROR] npm ERR!
[ERROR] npm ERR! Failed at the phantomjs-prebuilt@2.1.16 install script 'node install.js'.
[ERROR] npm ERR! This is most likely a problem with the phantomjs-prebuilt package,
[ERROR] npm ERR! not with npm itself.
[ERROR] npm ERR! Tell the author that this fails on your system:
[ERROR] npm ERR!     node install.js
[ERROR] npm ERR! You can get information on how to open an issue for this project with:
[ERROR] npm ERR!     npm bugs phantomjs-prebuilt
[ERROR] npm ERR! Or if that isn't available, you can get their info via:
[ERROR] npm ERR!
[ERROR] npm ERR!     npm owner ls phantomjs-prebuilt
[ERROR] npm ERR! There is likely additional logging output above.
[ERROR] npm verb exit [ 1, true ]
[ERROR] npm verb unbuild node_modules/karma-phantomjs-launcher/node_modules/phantomjs-prebuilt
[ERROR] npm info preuninstall phantomjs-prebuilt@2.1.16
[ERROR] npm info uninstall phantomjs-prebuilt@2.1.16
[ERROR] npm verb unbuild rmStuff phantomjs-prebuilt@2.1.16 from /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules
[ERROR] npm verb unbuild rmStuff in /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/karma-phantomjs-launcher/node_modules
[ERROR] npm verb gentlyRm vacuuming from /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/karma-phantomjs-launcher/node_modules/.bin/phantomjs up to /opt/modules/ambari/ambari-a
dmin/src/main/resources/ui/admin-web
[ERROR] npm info postuninstall phantomjs-prebuilt@2.1.16
[ERROR] npm verb gentlyRm don't care about contents; nuking /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/karma-phantomjs-launcher/node_modules/phantomjs-prebuilt
[ERROR] npm verb unbuild node_modules/karma-phantomjs-launcher
[ERROR] npm info preuninstall karma-phantomjs-launcher@1.0.4
[ERROR] npm info uninstall karma-phantomjs-launcher@1.0.4
[ERROR] npm verb unbuild rmStuff karma-phantomjs-launcher@1.0.4 from /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules
[ERROR] npm info postuninstall karma-phantomjs-launcher@1.0.4
[ERROR] npm verb gentlyRm don't care about contents; nuking /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/karma-phantomjs-launcher
[ERROR] npm verb unbuild node_modules/phantomjs
[ERROR] npm info preuninstall phantomjs@2.1.7
[ERROR] npm info uninstall phantomjs@2.1.7
[ERROR] npm verb unbuild rmStuff phantomjs@2.1.7 from /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules
[ERROR] npm verb gentlyRm vacuuming from /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/.bin/phantomjs up to /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web
[ERROR] npm info postuninstall phantomjs@2.1.7
[ERROR] npm verb gentlyRm don't care about contents; nuking /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/phantomjs
[ERROR]
[ERROR] npm ERR! Please include the following file with any support request:
[ERROR] npm ERR!     /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/npm-debug.log
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  55.502 s
[INFO] Finished at: 2024-10-24T01:16:25Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.3:npm (npm install) on project ambari-admin: Failed to run task: 'npm install --unsafe-perm --progress --save --verbose --registry=
https://registry.npmmirror.com/' failed. (error code 1) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.3:npm (npm install) on project ambari-admin: Failed to run task
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoFailureException: Failed to run task
    at com.github.eirslett.maven.plugins.frontend.mojo.AbstractFrontendMojo.execute (AbstractFrontendMojo.java:95)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException: 'npm install --unsafe-perm --progress --save --verbose --registry=https://registry.npmmirror.com/' failed. (error code 1)
    at com.github.eirslett.maven.plugins.frontend.lib.NodeTaskExecutor.execute (NodeTaskExecutor.java:60)
    at com.github.eirslett.maven.plugins.frontend.mojo.NpmMojo.execute (NpmMojo.java:62)
    at com.github.eirslett.maven.plugins.frontend.mojo.AbstractFrontendMojo.execute (AbstractFrontendMojo.java:89)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

1.1 错误定位

从日志中可以看出,phantomjs-prebuilt 在尝试下载 phantomjs 文件时失败,导致安装中断。

在这里插入图片描述

2. 解决方案 💡

2.1 通过日志中的命令重复执行

在这里插入图片描述

为进一步定位错误,可以按照以下步骤操作:

# Step 1: 进入工作空间
cd /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web

# Step 2: 执行命令尝试安装
/opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node/node /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node/node_modules/npm/bin/npm-cli.js install --unsafe-perm --progress --save --verbose --registry=https://registry.npmmirror.com/

# 如果不想进入目录,可以尝试添加 --prefix 参数
/opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node/node /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node/node_modules/npm/bin/npm-cli.js install --unsafe-perm --progress --save --verbose --registry=https://registry.npmmirror.com/ --prefix /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web

2.2 结果分析

在这里插入图片描述

通过执行上述命令后,我们发现 PhantomJS 文件下载过程中,网络问题导致失败:

npm verb readDependencies loading dependencies from /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/karma/node_modules/log4js/node_modules/hipchat-notifier/node_modules/request
/node_modules/http-signature/node_modules/sshpk/node_modules/tweetnacl/package.json
npm info linkStuff gulp-uglify@0.2.1
npm info install phantomjs-prebuilt@2.1.16
npm verb rebuildBundles [ 'is-descriptor' ]
npm info install define-property@0.2.5
npm verb readDependencies loading dependencies from /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/karma/node_modules/log4js/node_modules/loggly/node_modules/request/node_modu
les/http-signature/node_modules/sshpk/node_modules/assert-plus/package.json
npm info linkStuff is-descriptor@0.1.7
npm info linkStuff is-descriptor@0.1.7
npm verb rebuildBundles [ 'is-descriptor' ]
npm info install define-property@0.2.5
npm info postinstall performance-now@2.1.0
npm verb unlock done using /root/.npm/_locks/asn1-f6e4cd98c90ee378.lock for /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/karma/node_modules/log4js/node_modules/hipchat-notif
ier/node_modules/request/node_modules/http-signature/node_modules/sshpk/node_modules/asn1

> phantomjs-prebuilt@2.1.16 install /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node_modules/karma-phantomjs-launcher/node_modules/phantomjs-prebuilt
> node install.js

PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...
  [----------------------------------------] 0%

从日志可以看到下载目标目录是 /tmp/phantomjs,由于网络问题导致下载失败。我们可以尝试更换下载地址。


2.3 更换下载地址

通过设置 PHANTOMJS_CDNURL 环境变量,可以修改 PhantomJS 的下载源:

# 配置环境变量
export PHANTOMJS_CDNURL=https://npmmirror.com/mirrors/phantomjs/

# 尝试重新安装
/opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node/node /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web/node/node_modules/npm/bin/npm-cli.js install --unsafe-perm --progress --save --verbose --registry=https://registry.npmmirror.com/ --prefix /opt/modules/ambari/ambari-admin/src/main/resources/ui/admin-web

解读:为什么使用 PHANTOMJS_CDNURL

PHANTOMJS_CDNURLphantomjs-prebuilt 包安装过程中用于指定下载源的环境变量。在 install.js 脚本中,安装程序会检查是否存在 PHANTOMJS_CDNURL,如果找到这个变量,它会将其作为下载 URL 的前缀地址。

在这里插入图片描述

在这里插入图片描述

核心代码:

var cdnUrl = process.env.npm_config_phantomjs_cdnurl ||
      process.env.PHANTOMJS_CDNURL ||
      DEFAULT_CDN

这种逻辑意味着,如果我们设置了 PHANTOMJS_CDNURL,安装脚本会优先从自定义的下载源获取 PhantomJS 文件,而不是从默认的官方源下载。

为什么要这样做?
在国内网络环境中,直接从官方 GitHub 源下载文件可能会因为网络问题导致速度缓慢或下载失败。通过指定 https://npmmirror.com/mirrors/phantomjs/ 这样一个国内镜像站点,可以加快下载速度,确保安装顺利完成。PHANTOMJS_CDNURL 的设计正是为了给用户提供这种灵活性,让用户根据网络环境自由调整下载源。

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

2.4 补充知识

在这里插入图片描述

当我们重复执行安装时,如果本地已经存在该安装包,将不会从网上重新下载。因此,我们还可以手动下载 PhantomJS 文件并将其放入 /tmp/phantomjs 目录。

3. 我的解决方案(懒人办法)💡🚀

在这里插入图片描述

我选择在编译框架中直接处理环境变量,将 PhantomJS 的下载源修改为国内镜像,以避免网络问题带来的安装失败。

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TTBIGDATA

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值