【问题标题】:Warning: PhantomJS not found警告:找不到 PhantomJS
【发布时间】:2013-08-15 14:28:11
【问题描述】:

我已经在 debian 6 上安装了 nodejs 0.10.15。然后我使用 npm 安装了:

sudo npm install grunt-cli -g

我还在本地测试目录中执行了 npm install(将必要的依赖项下载到 node_modules 目录),其中包含以下 package.json 文件:

{
  "name": "sample-name",
  "version": "1.4.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-qunit": ">0.0.0",
    "grunt-qunit-istanbul": ">0.0.0"
  }
}

这是安装phantomjs时的输出:

...
Writing location.js file
Done. Phantomjs binary available at /home/myuser/Test/node_modules/grunt-contrib-qunit/node_modules/grunt-lib-phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs
Done. Phantomjs binary available at /home/myuser/Test/node_modules/grunt-qunit-istanbul/node_modules/grunt-lib-phantomjs-istanbul/node_modules/phantomjs/lib/phantom/bin/phantomjs
grunt@0.4.1 node_modules/grunt
├── which@1.0.5
...

但是当我从测试目录运行 grunt test 时,我得到:

Running PhantomJS...ERROR
>> In order for this task to work properly, PhantomJS must be installed locally
>> via NPM. If you're seeing this message, generally that means the NPM install
>> has failed. Please submit an issue providing as much detail as possible at:
>> https://github.com/gruntjs/grunt-lib-phantomjs/issues
Warning: PhantomJS not found. Use --force to continue.

如果我运行安装在先前指定位置的 phantomjs 脚本,则没有任何反应,但我得到退出代码 127(表示问题 PATH:http://tldp.org/LDP/abs/html/exitcodes.html)。如果我 cat phantomjs bash 脚本,它看起来像这样:

#!/usr/bin/env node

var path = require('path')
var spawn = require('child_process').spawn

var binPath = require(path.join(__dirname, '..', 'lib', 'phantomjs')).path

var args = process.argv.slice(2)

// For Node 0.6 compatibility, pipe the streams manually, instead of using
// `{ stdio: 'inherit' }`.
var cp = spawn(binPath, args)
cp.stdout.pipe(process.stdout)
cp.stderr.pipe(process.stderr)
cp.on('exit', process.exit)

process.on('SIGTERM', function() {
  cp.kill('SIGTERM')
  process.exit(1)
})

据我了解,这意味着 phantomjs 在节点内部执行。如果我启动节点输入我得到的路径变量:

:~$ env node
> var path = require('path')
undefined
> 

(我理解为默认行为:node.js displays "undefined" on the console

有什么建议可以进一步调试这个问题?

【问题讨论】:

  • 你的项目文件夹层次结构是什么? phantomjs 在这个层次结构中的什么位置?
  • 测试位于此处:/home/myuser/Test/ 并且 phantomjs 位于上述目的地(运行 npm install 的输出)

标签: node.js debian phantomjs


【解决方案1】:

尝试运行

npm uninstall phantomjs

然后运行

npm install phantomjs -g

这应该确保 phantom 与命令行一起安装,以便 grunt 可以使用它,并且还应该确保它安装干净。

【讨论】:

  • 应该从哪里执行?我得到:module.js:340 抛出错误; ^ 错误:从终端运行时在 Function.Module._resolveFilename (module.js:338:15) 处找不到模块“/home/myuser/Test/install”
  • @jserup 应该和 grunt 在同一个目录下执行,这个目录应该和你项目的顶级目录一致。在任何地方都应该有一个node_modules 文件夹,以及您的package.json
  • 你不是说“npm uninstall phantomjs”和“npm install phantomjs -g”而不是“node”吗?使用 npm 我可以在目录的根目录中卸载并重新安装它,但是当我运行“grunt test”时我仍然遇到同样的错误:警告:找不到 PhantomJS。使用 --force 继续。
  • @jserup 感谢您的提醒!显然我需要更多的咖啡。
  • 嗯从debian 6升级到7后问题消失了。
【解决方案2】:

试试 npm install grunt-mocha -D

https://github.com/gruntjs/grunt-lib-phantomjs/issues/22查看更多详情

【讨论】:

  • 不起作用。执行该命令时出现相同的错误。
【解决方案3】:

尝试在终端中运行以下命令:

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

【讨论】:

    猜你喜欢
    • 2013-01-27
    • 2023-03-28
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 2013-06-08
    • 2015-06-11
    • 2015-07-23
    相关资源
    最近更新 更多