Cannot start Chrome / Cannot start Firefox errors

2019-08-02 02:11发布

问题:

I am following the Angular Tutorial at https://docs.angularjs.org/tutorial/step_02.

I want to run the following command:

npm test
karma start karma.conf.js

And getting the following error:

> karma start karma.conf.js

WARN [watcher]: Pattern "/var/angularapp/angular-phonecat/app/**/*.module.js" does not match any file.
WARN [watcher]: Pattern "/var/angularapp/angular-phonecat/app/!(bower_components)/**/*!(.module|.spec).js" does not match any file.
WARN [karma]: No captured browser, open http://localhost:9876/
INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
INFO [launcher]: Starting browser Firefox
INFO [launcher]: Starting browser Chrome
ERROR [launcher]: Cannot start Firefox

INFO [launcher]: Trying to start Firefox again (1/2).
ERROR [launcher]: Cannot start Firefox

INFO [launcher]: Trying to start Firefox again (2/2).
17 08 2016 18:46:51.434:ERROR [launcher]: Cannot start Firefox

ERROR [launcher]: Firefox failed 2 times (cannot start). Giving up.
ERROR [launcher]: Cannot start Chrome

INFO [launcher]: Trying to start Chrome again (1/2).
ERROR [launcher]: Cannot start Chrome

[launcher]: Trying to start Chrome again (2/2).
[launcher]: Cannot start Chrome

ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up.

karma.config.js:

browsers: ['Firefox', 'Chrome'],

I installed Firefox and Chrome using the following commands:

 sudo apt-install chromium-browser
 sudo apt-install firefox

And set the env variables in ~/.bachrc:

export FIREFOX_BIN=/usr/bin/firefox
export CHROME_BIN=/usr/bin/chromium-browser

I even typed the following command, but did not help:

source ~/.bashrc

My node version is 0.12.15 and npm is 2.15.1. Please note that this is a vagrant box that I am talking about.

Please help :)

回答1:

Someone suggested that I should use Phantomjs instead! So I did it and below is what I did exactly and made the test pass:

Install PhantomJS:

sudo npm install -g phantomjs-prebuilt

Update the env variable by adding the following line to ~/.bashrc:

export PHANTOMJS_BIN=/usr/bin/phantomjs

Add the following line to devdependencies in package.json file within the project:

"karma-phantomjs-launcher": "^0.2.0",

Add the following line to karma.config.js file:

plugins: [
  ...
      'karma-phantomjs-launcher',
  ...
    ]

And finally change the browsers in karma.config.js to be:

browsers: ['PhantomJS'],

However, I still do not know why Chrome and Firefox did not work, and Phantomjs did the job. The way I view it is my vagrant box is just an Ubuntu machine, and should not be different than any other machines! It would be great if someone explains to me the reasons. And please consider that I am a newbie.



回答2:

I've posted an answer in the related thread: Karma - Chrome failed 2 times (cannot start). Giving up

Basically, for me chrome was not able to start because fonts were missing.



回答3:

The tests weren't running for me either. I changed the following in karma.conf.js to so that Karma would only try to use Chrome:

browsers: ['Chrome'],

plugins: [
  'karma-chrome-launcher',
  'karma-jasmine'
]

I'm assuming that not having Firefox installed on my machine was causing Karma to fail.