19

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

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:

{
  "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:

...
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
...

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

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:

#!/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:

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

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

Any suggestions to further debug this problem?

4

3 回答 3

32

尝试运行

npm uninstall phantomjs

然后运行

npm install phantomjs -g

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

于 2013-08-14T06:21:28.837 回答
9

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

npm install phantomjs-prebuilt@2.1.14 --ignore-scripts
于 2017-06-09T06:55:14.270 回答
2

尝试 npm install grunt-mocha -D

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

于 2014-05-10T13:28:15.407 回答