无法使用 npm 在 Windows 上安装 Phantomjs

Can't Install Phantomjs on Windows with npm

所以我正在尝试在工作时安装 phantom.js。我可以下载它的源代码,甚至可以为它安装 .exe(这样我就可以访问 phantom shell)。但它仍然没有安装。当我尝试 node ./install .js 或 npm install phantom.js 时,出现此错误。

connect ETIMEDOUT ip:port
This is most likely not a problem with npm itself
and is related to network connectivity.
In most cases you are behind a proxy or have bad network settings.

If you are behind a proxy, please make sure that the
'proxy' config is set properly.  See: 'npm help config'

Receiving...

Error making request.

Error: connect ETIMEDOUT ipaddress:port

at Object.exports._errnoException (util.js:860:11)

at exports._exceptionWithHostPort (util.js:883:20)

at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)

我的节点版本是 v4.4.2,我在 Windows 7.

我已尝试编辑我的 .npmrc 文件(包含我的代理信息的文件),以便它现在具有以下行 phantomjs_cdnurl=https://cnpmjs.org/downloads

我也试过将 .exe 文件添加到我的 PATH 和源代码中,但仍然没有成功。最后,我尝试了 README 建议的内容,例如 shell 命令,如 "npm install phantomjs-prebuilt --phantomjs_cdnurl=https://bitbucket.org/ariya/phantomjs/downloads",但也有相同的错误。我有什么地方 missing/done 错了吗?帮助将不胜感激。

此处最简单的解决方案是将 PhantomJS 文件夹正确添加到 PATH 环境变量。例如,如果最初你有这样的路径:

C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Python27\;C:\Python27\Scripts;C:\Program Files\TortoiseHg\

然后添加一个分号和 PhantomJS 所在的文件夹 的路径,而不是 .exe 本身。所以假设 PhantomJS 在 C:\Phantomjs\phantom.exe 你只添加 ;C:\Phantomjs\:

C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Python27\;C:\Python27\Scripts;C:\Program Files\TortoiseHg\;C:\Phantomjs\

然后按确定,然后关闭命令提示符并再次打开它以便它读取更新的 PATH。之后,您可以在任何地方通过名称 phantom(如果它被称为 phantom.exe)调用它来自由使用 phantomjs。

我发现最好的办法就是使用 phantomjs-that-works

  npm install -g phantomjs-that-works