26

My package.json looks like this..

"karma-phantomjs-launcher": "^0.1.4",
"karma-safari-launcher": "^0.1.1",
"karma-sinon-chai": "~0.2.0",
"karma-spec-reporter": "~0.0.16",
"mocha": "~1.20.1"

my npm version is 2.2.0

whay am I getting this when I run karma test - karma start my.conf.js

Sanath
  • 4,774
  • 10
  • 51
  • 81
  • 3
    The message is pretty clear: there's no PhantomJS installed on your machine. `karma-phantomjs-launcher` should download a binary of PhantomJS and install on your machine if available: because it's not you have to manually install yourself and then add its path to the environment variables using the `PHANTOMJS_BIN`. – MarcoL Feb 05 '15 at 09:19
  • 1
    @MarcoCI I do have the same problem and there actually is a binary of phantomjs being installed together with the `karma-phantomjs-launcher`. – F Lekschas Mar 23 '15 at 19:51
  • 1
    @Flek: then export the path of that file as shown in the answer below. – MarcoL Mar 25 '15 at 06:30
  • I fixed it by removing karma-phantomjs-launcher and phantomjs and running npm install – crowne Jul 25 '16 at 04:25

11 Answers11

19

This seems to be an issue with phantom js runner and phantom js versions.

https://github.com/karma-runner/karma-phantomjs-launcher/issues/31

How I fixed my issue..

   # install 
   npm install -g karma-phantomjs-launcher

   # temporary path.. set the path
   export PHANTOMJS_BIN=/usr/local/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs

   karma start my.conf.js
Michiel Kalkman
  • 3,054
  • 24
  • 25
Sanath
  • 4,774
  • 10
  • 51
  • 81
16

I was having this issue with an older version of node, too. If you don't want to have to hard-code this environment variable, updating your version of node will solve the problem. Just do the following (OSX instructions):

npm uninstall -g phantomjs
npm cache clean -f
brew upgrade nodejs
rm -rf node_modules
npm install -g YOUR_GLOBAL_DEPENDENCIES
npm install

Edit: updated instructions to make sure there is no global phantomjs dependency

Dan Caddigan
  • 1,578
  • 14
  • 25
  • These commands initially seemed to cause more problems then solutions but I eventually worked through them. `brew upgrade nodejs` didn't work out for me, I got `Error: node not installed`. But it seems that just unistalling phantomjs, cleaning npm cache, and reinstalling packages with npm cleared my `No binary for PhantomJS browser on your platform. Please, set “PHANTOMJS_BIN” env variable` error. Thank you! – Mike Mar 08 '16 at 23:48
  • exactly why i didnt want to embark on them. i physically downgraded node to cure another problem. no time for that tonite – blamb Aug 30 '16 at 05:58
  • I am able to do this for the first time, but every time I close my system and restart the app, I have to do this again. Is there a way to permanently get rid of this error? – thenakulchawla Oct 19 '16 at 00:11
  • I also ran into issues with npm after doing the upgrade... `npm install` would simply quit after a deprecation warning. Physically downloading the latest from [nodejs.org](https://nodejs.org/en/) fixed it for me – ironic_ollins Jan 05 '17 at 16:04
12

I ran into this same problem. The fix is to manually set the PHANTOMJS_BIN variable to point to the correct phantomjs path. Somehow karma launcher tries to look at the wrong path set by PHANTOMJS_BIN.

Here is what worked for me:

$ echo $PHANTOMJS_BIN

/usr/local/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs

$ export PHANTOMJS_BIN=/usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs

$ grunt test

everything is ok after that.

sudo bangbang
  • 27,127
  • 11
  • 75
  • 77
Harry Che
  • 171
  • 1
  • 8
4

I hit this problem with karma-phantomjs-launcher@1.0.0, where I had also installed phantomjs@2.1.3.

Turns out that phantomjs is deprecated, replaced with phantomjs-prebuilt.

Uninstalling both packages and reinstalling phantomjs-prebuilt fixed the problem with karma-phantomjs-launcher:

npm -g remove phantomjs phantomjs-prebuilt
npm -g install phantomjs-prebuilt
DJ Lee
  • 41
  • 1
4

I remove all my node_modules folder under my Project and run "npm install". This did fix my problem.

Dom
  • 41
  • 4
2

My karma.conf.js had this line: process.env.PHANTOMJS_BIN = 'node_modules/karma-phantomjs-launcher/node_modules/.bin/phantomjs'; at the top. I just realized that! I commented it, and it works

Mati Tucci
  • 2,826
  • 5
  • 28
  • 40
2

I met the same issue sometimes. I have a gruntfile.js and I had package.json where I explicitly add phantomjs-prebuilt as dependency. But my CI Server sometimes can run grunt karma smoothly while sometimes fails claiming No binary for PhantomJS browser on your platform. Please, set “PHANTOMJS_BIN” env variable.

So I add a grunt task to ensure the PHANTOMJS_BIN variable was set before the test runs, and then solved the annoying issue.

grunt.registerTask('ensurePhantomJsPath', function () {
    process.env.PHANTOMJS_BIN = './node_modules/phantomjs-prebuilt/bin/phantomjs';
    console.log(process.env.PHANTOMJS_BIN);
});

So finally the Gruntfile.js looks like this:

grunt.registerTask('ensurePhantomJsPath', function () {
    process.env.PHANTOMJS_BIN = './node_modules/phantomjs-prebuilt/bin/phantomjs';
    console.log(process.env.PHANTOMJS_BIN);
});

grunt.registerTask('test', ['ensurePhantomJsPath', 'karma']);
Jeff Tian
  • 5,210
  • 3
  • 51
  • 71
2

I solved this problem on OSX: Remove and create file karma.config.js using sudo.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
1

had same problem, did all above, no result just deleted 'karma-phantomjs-launcher' folder from global node_modules and project local, called 'npm install' and all is fine!

Dmitri Algazin
  • 3,332
  • 27
  • 30
1

Ran into a problem like this one. What I did was install the phantomjs globally npm install -g phantomjs. Then went to the karma-phantomjs-launcher module folder and opened index.js file. Then I went to the phantomJSExePath function and commented out the prior contents(not sure if it is safe to do what I did). Then I placed

return 'C://Users/user/AppData/Roaming/npm/node_modules/phantomjs/lib/phantom/phantomjs.exe';

Saved me from retyping the temporary export.

sudo bangbang
  • 27,127
  • 11
  • 75
  • 77
f123
  • 382
  • 2
  • 9
1

Run the below commands:

npm remove phantomjs -g
npm remove phantomjs
npm install phantomjs

Once you do this installation:

you will get a message like the below one:

Linking to global install at /usr/local/lib/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs

Copy this path and run:

export PHANTOMJS_BIN=/usr/local/lib/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs

Basically what is happening is: karma is trying to launch the browser but unable to find its bin. Once you export the path to the correct path, it runs.

agriboz
  • 4,724
  • 4
  • 35
  • 49
thenakulchawla
  • 5,024
  • 7
  • 30
  • 42