node.js 警告:找不到 PhantomJS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18218134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:18:21  来源:igfitidea点击:

Warning: PhantomJS not found

node.jsdebianphantomjs

提问by so12345

I have installed nodejs 0.10.15 on debian 6. Using npm I have then installed:

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

sudo npm install grunt-cli -g

I have also executed npm install in my local test directory (downloading the necessary dependencies to the node_modules directory) which contains the following package.json file:

我还在我的本地测试目录中执行了 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"
  }
}

here is the output when installing phantomjs:

这是安装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
[email protected] node_modules/grunt
├── [email protected]
...

But when I run grunt testfrom the test dir I get:

但是当我从测试目录运行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.

If I run the phantomjs script installed in the previous specified location nothing happens, I get exit code 127 though (indicating problem PATH :http://tldp.org/LDP/abs/html/exitcodes.html). If I cat the phantomjs bash script it looks like this:

如果我运行安装在先前指定位置的 phantomjs 脚本,则没有任何反应,但我会得到退出代码 127(表示问题路径: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)
})

As I understand this means that phantomjs is executed inside node. If I start node enter the path var I get:

据我了解,这意味着 phantomjs 在 node.js 中执行。如果我开始节点输入路径 var 我得到:

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

(which I understand is default behavior: node.js displays "undefined" on the console)

(我理解这是默认行为:node.js 在控制台上显示“未定义”

Any suggestions to further debug this problem?

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

回答by Brandon Anzaldi

Try running

尝试跑步

npm uninstall phantomjs

npm uninstall phantomjs

then running

然后运行

npm install phantomjs -g

npm install phantomjs -g

This should make sure phantom's installed with the command line, so that grunt can use it, and also should make sure that it installed cleanly.

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

回答by Chevdor

Try npm install grunt-mocha -D

尝试 npm install grunt-mocha -D

See more details at https://github.com/gruntjs/grunt-lib-phantomjs/issues/22

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

回答by Hyman

Try running the following in your terminal:

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

npm install [email protected] --ignore-scripts