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?

Community
  • 1
  • 1
so12345
  • 565
  • 1
  • 5
  • 12
  • What is your projects folder hierarchy and where is phantomjs in this hierarchy? – dc5 Aug 13 '13 at 23:53
  • Tests are located here: /home/myuser/Test/ and phantomjs is located in the above destination (output from running npm install) – so12345 Aug 14 '13 at 07:53

3 Answers3

36

Try running

npm uninstall phantomjs

then running

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.

Brandon Anzaldi
  • 6,884
  • 3
  • 36
  • 55
  • Where should that be executed from? I get: module.js:340 throw err; ^ Error: Cannot find module '/home/myuser/Test/install' at Function.Module._resolveFilename (module.js:338:15) when running from terminal – so12345 Aug 14 '13 at 07:51
  • @jserup It should be executed from the same directory that grunt is, which should coincide with the top level directory of your project. There should be a `node_modules` folder in whereever that is, as well as your `package.json`. – Brandon Anzaldi Aug 14 '13 at 08:52
  • 1
    You don't mean "npm uninstall phantomjs" and "npm install phantomjs -g" instead of "node"? Using npm I can uninstall and reinstall it in the root of the directory but I still get the same error when I run "grunt test" : Warning: PhantomJS not found. Use --force to continue. – so12345 Aug 14 '13 at 20:40
  • @jserup Thanks for the heads up! Apparently I needed more coffee. – Brandon Anzaldi Aug 14 '13 at 23:35
  • 1
    Hm after upgrading from debian 6 to 7 the problem disappeared. – so12345 Aug 18 '13 at 20:39
  • Doesn't work. Get the same error when executing that command. – Martijn Hiemstra Jan 18 '22 at 13:22
  • This helped me with macOS. – Rone Clay Brasil May 26 '22 at 20:59
10

Try running the following in your terminal:

npm install phantomjs-prebuilt@2.1.14 --ignore-scripts
jack
  • 101
  • 1
  • 2
2

Try npm install grunt-mocha -D

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

Chevdor
  • 664
  • 4
  • 12