在 phantomjs-prebuilt@2.1.13 安装脚本"节点安装.js"失败



我正在尝试在Windows 7机器上安装phantomjs,但收到此错误。

npm ERR! Windows_NT 6.1.7601  
npm ERR! argv "C:\Program Files (x86)\nodist\v\nodev5.5.0\node.exe"   "C:\Program Files (x86)\nodist\bin\node_mod  
ules\npm\bin\npm-cli.js" "install"  
npm ERR! node v5.5.0  
npm ERR! npm  v3.10.9  
npm ERR! code ELIFECYCLE  
npm ERR! phantomjs-prebuilt@2.1.13 install: `node install.js`  
npm ERR! Exit status 1  
npm ERR!  
npm ERR! Failed at the phantomjs-prebuilt@2.1.13 install script 'node   install.js'.  
npm ERR! Make sure you have the latest version of node.js and npm installed.

对于相同或这个SO问题,phantomjs github存储库中记录了许多问题,但就我而言,这些问题都没有帮助。

这是我的机器的状态

  • 我在C:pm\phantomjs-2.1.1-windows\bin\phantomjs本地安装了 phantomjs.exe但是当我运行 npm 安装时,它总是会尝试通过下载进行安装,这对我来说是问题所在。我的公司代理正在阻止直接下载。我也不能使用这里提到的--phantomjs_cdnurl开关 https://www.npmjs.com/package/phantomjs#deciding-where-to-get-phantomjs
  • 我可以运行该命令,它工作正常phantomjs -v
    2.1.1

但是当我在我的项目上运行npm install时,它正在尝试安装 phantomjs 并会遇到上述错误。我从 npm 日志中观察到的另一件事

Considering PhantomJS found at C:Program Files (x86)nodistbinphantomjs.CMD Found PhantomJS at C:Program Files (x86)nodistbinphantomjs.CMD ...verifying Error verifying phantomjs, continuing { [Error: Command failed: C:Program Files (x86)nodistbinphantomjs.CMD --version

它正在尝试运行PhantomJS。CMD --版本也失败了

Error verifying phantomjs, continuing { [Error: Command failed: C:Program Files (x86)nodistbinphantomjs.CMD --versio
n
internal/child_process.js:274
var err = this._handle.spawn(options);
^
TypeError: Bad argument
at TypeError (native)
at ChildProcess.spawn (internal/child_process.js:274:26)
at exports.spawn (child_process.js:362:9)
at Object.<anonymous> (C:Program Files (x86)nodistbinnode_modulesphantomjs-prebuiltbinphantomjs:22:10)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:139:18)
]
killed: false,
code: 1,
signal: null,
cmd: 'C:\Program Files (x86)\nodist\bin\phantomjs.CMD --version' }

作为临时解决方法,我能够使用 --ignore-scripts 安装它

npm install phantomjs-prebuilt@2.1.13 --ignore-scripts

我还在 github 存储库中记录了一个问题

https://github.com/Medium/phantomjs/issues/649

编辑

这个问题是我正在使用的构建过程脚本的一部分,它每次都会使用一堆其他东西进行 npm 清理和安装。因此,此问题在我们使用phantomjs自动测试的同一台机器中多次出现。我有一些时间来研究这个问题,似乎我的公司代理阻止了 https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-windows.zip 下载。我之前知道这一点,并手动安装了phantomjs二进制文件并添加到系统路径中,但是npm安装仍在尝试在本地下载,如下面的日志所示。

Considering PhantomJS found at C:npmphantomjs-2.1.1-windowsbinphantomjs.EXE
Looks like an `npm install -g` on windows; skipping installed version.

我的公司代理也阻止了所有幻影 CDN 网址 (https://www.npmjs.com/package/phantomjs)

我使用的解决方法是获取phantomjs-2.1.1-windows.zip并将其复制到C:\Users\\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip这解决了构建脚本的问题。如果有人清理临时目录,问题将再次出现。即使这是一个解决方法,但由于明显的原因,公司代理无法解锁:)

希望这对某人有所帮助!

有时当我们尝试在本地安装 phantomjs 时,它会起作用。但是对于全局,我建议您键入

sudo npm install -g phantomjs-prebuilt --unsafe-perm

遇到了同样的错误,通过以下更改来解决,希望对您有所帮助。

sudo npm install phantomjs-prebuilt@2.1.13 --unsafe-perm

请删除系统中连接的任何VPN。我删除了办公室VPN,然后点击npm install它对我来说效果很好。

所有这些解决方案都没有帮助我

--忽略脚本有帮助,但最终安装的PhantomJS是行不通的,我的业力测试无法使用PhantomJS浏览器。

但是,我为我的Win机器找到了解决方案。我从https://phantomjs.org/download.html下载了带有.exe文件的分发,然后在本地解压缩(它可以是任何文件夹):

然后添加到:set Path=;C:UsersadminAppDataRoamingphantomjs-2.1.1-windowsbin;$Path

在那之后,"npm 安装"能够重用它:

[exec] > node install.js
[exec] 
[exec] Considering PhantomJS found at C:UsersadminAppDataRoamingphantomjs-2.1.1-windowsbinphantomjs.EXE
[exec] Found PhantomJS at C:UsersadminAppDataRoamingphantomjs-2.1.1-windowsbinphantomjs.EXE ...verifying
[exec] Writing location.js file
[exec] PhantomJS is already installed on PATH at C:UsersadminAppDataRoamingphantomjs-2.1.1-windowsbinphantomjs.EXE
[exec] 
[exec] > phantomjs@2.1.7 install C:xxxclientuisrcmainwebbuildnode_modulesphantomjs
[exec] > node install.js

最新更新