“Cannot start Chrome” error with Yeoman

2020-02-29 11:04发布

问题:

I'm trying to start using Yeoman (it seems awesome indeed) and having an error trying to run the grunt test command.

Running "karma:unit" (karma) task
INFO [karma]: Karma server started at http://localhost:8080/
INFO [launcher]: Starting browser Chrome
WARN [watcher]: Pattern "/home/jaywalking101/Dropbox/demokritos/test/mock/**/*.js" does not match any file.
ERROR [launcher]: Cannot start Chrome
    Can not find the binary google-chrome
    Please set env variable CHROME_BIN
Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.

A search didn't help me much. I found some references to similar problems but nothing clear enough (to my current knowledge). Any clues? Solutions? Anything?

I'm on Lubuntu, Node.js 0.10.15, Yeoman 1.0RC4.

Update

For anyone else as lost as I was, the following question, Testacular error: Cannot start chrome, made me start thinking there is no Chrome Browser on Ubuntu, but there is Chromium. And although it's not in the supported browsers list on karma code it seems to be a valid option.

Like this:

browsers = ['chromium-browser'];

The question I mentioned before talks about testacular, but the solution worked just fine for me with karma. (perhaps they are the same thing somehow. I really do not know much about these subjects yet).

回答1:

It's fairly clear from the error message that it can't find google-chrome, which is set as the browser in your Karma config. You either need to change this to another browser or manually set the path to the Chrome binary using the CHROME_BIN environment variable.



回答2:

this worked for me on ubuntu 12.04

echo 'export CHROME_BIN="/usr/bin/chromium-browser"' >> ~/.bashrc && source ~/.bashrc


回答3:

Expanding on the above, for Linux systems, you can point the CHROME_BIN env variable to the chromium binary:

export CHROME_BIN="/usr/bin/chromium-browser"


回答4:

Alternatively, instead of setting the env variable globally, you can set it only for the command you're running:

CHROME_BIN=chromium-browser grunt test