phantomjs下载失败问题
# 解决 PhantomJS 下载失败问题及 Node.js 多版本管理方案
# 1、问题剖析
# 1.1 PhantomJS 下载失败
编译Ambari过程中如果遇到如下问题,可以尝试解决下载失败问题。
verbose 51.4189986 Error: D:\person\bigdata\ambari-2.8.0\ambari-web\node_modules\phantomjs: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: D:\person\bigdata\ambari-2.8.0\ambari-web\node_modules\phantomjs
Output:
PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1//phantomjs-2.1.1-windows.zip
Saving to C:\Users\tt\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip
Receiving...
Error making request.
Error: connect ETIMEDOUT 140.82.113.3:443
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
Please report this full log at https://github.com/Medium/phantomjs
at ProcessTermError.ExtendableBuiltin (D:\Program Files\nvm\v18.20.4\node_modules\yarn\lib\cli.js:721:66)
at ProcessTermError.MessageError (D:\Program Files\nvm\v18.20.4\node_modules\yarn\lib\cli.js:750:123)
at new ProcessTermError (D:\Program Files\nvm\v18.20.4\node_modules\yarn\lib\cli.js:790:113)
at ChildProcess.<anonymous> (D:\Program Files\nvm\v18.20.4\node_modules\yarn\lib\cli.js:25789:17)
at ChildProcess.emit (node:events:517:28)
at maybeClose (node:internal/child_process:1098:16)
at ChildProcess._handle.onexit (node:internal/child_process:303:5)
error D:\person\bigdata\ambari-2.8.0\ambari-web\node_modules\phantomjs: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: D:\person\bigdata\ambari-2.8.0\ambari-web\node_modules\phantomjs
Output:
PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1//phantomjs-2.1.1-windows.zip
Saving to C:\Users\tt\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip
Receiving...
Error making request.
Error: connect ETIMEDOUT 140.82.113.3:443
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Process finished with exit code 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
原因: 由于访问 GitHub 的速度较慢或网络超时,导致无法从 GitHub 下载 PhantomJS。
# 2、解决办法
# 2.1 代理下载并手动安装 PhantomJS
如果 PhantomJS 下载失败,可以通过代理下载并手动安装:
# 2.1.1 代理下载链接
通过 ghproxy
镜像,下载 PhantomJS Windows 版本:
下面的链接挂了代理-如果链接失效,可以联系作者
PhantomJS 2.1.1 Windows 版下载 (opens new window)
下载后,将文件解压到指定目录。
# 2.1.2 手动安装
- 将 PhantomJS 解压到指定目录,如
C:\phantomjs
。 - 将该目录添加到系统
PATH
环境变量中。 - 验证 PhantomJS 安装是否成功:
phantomjs --version
1
# 2.2 配置 npm 和 yarn 镜像源
由于国内访问 GitHub 及 npm 仓库速度较慢,配置国内镜像源能显著提高下载速度。
# 2.2.1 设置 npm 和 yarn 镜像源
# 设置 npm 使用淘宝镜像源
npm config set registry https://registry.npmmirror.com
# 设置 yarn 使用淘宝镜像源
yarn config set registry https://registry.npmmirror.com
1
2
3
4
5
2
3
4
5
# 2.3 清理缓存
清理 npm 或 yarn 缓存,确保安装依赖时不会遇到缓存相关的问题:
# 清理 npm 缓存
npm cache clean --force
# 清理 yarn 缓存
yarn cache clean
1
2
3
4
5
2
3
4
5
# 2.4 安装依赖并启动
完成 PhantomJS 安装并配置镜像源后,重新安装项目依赖:
# 安装所有依赖
yarn install --verbose
# 启动项目
npm run start
1
2
3
4
5
2
3
4
5