phantomjs cannot start up

ε祈祈猫儿з 提交于 2019-12-23 09:18:23

问题


I used AngularJS in my project and karma to test. Then I configured karma like this:

config.set({
    basePath: '../',
    frameworks: ['jasmine'],
    files: [
        // bower:js
        'bower_components/jquery/dist/jquery.js',
        'bower_components/angular/angular.js',
        'bower_components/bootstrap/dist/js/bootstrap.js',
        'bower_components/angular-animate/angular-animate.js',
        'bower_components/angular-cookies/angular-cookies.js',
        'bower_components/angular-route/angular-route.js',
        'bower_components/angular-sanitize/angular-sanitize.js',
        'bower_components/angular-mocks/angular-mocks.js',
        // endbower
        'js/**/*.js',
        'test/spec/**/*.js'
    ],
    browsers: [
        'PhantomJS'
    ],
    plugins: [
        'karma-phantomjs-launcher',
        'karma-jasmine'
    ],
    port: 8890

})

And grunt like this:

grunt.initConfig({
    connect: {
        testserver: {
            options: {
                base: 'js/',
                hostname: 'localhost',
                port: '8889'
            }
        }
    },
    karma: {
        unit: {
            configFile: './test/karma-unit.conf.js',
            singleRun: true
        }
    } 
});

grunt.registerTask('test', ['connect', 'karma:unit']);

When I type 'grunt test', the console shows that phantomjs cannot start:

Running "connect:testserver" (connect) task
Started connect web server on http://localhost:8889

Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.31 server started at http://localhost:8890/
INFO [launcher]: Starting browser PhantomJS
ERROR [launcher]: Cannot start PhantomJS

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

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

ERROR [launcher]: PhantomJS failed 2 times (cannot start). Giving up.
Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.

How can I solve this? Can anybody help me?


回答1:


I ran into this too, seemed to be an issue with where karma-phantomjs2-launcher looks for the phantomjs executable. It uses PHANTOMJS_BIN to run phantomjs, so I solved it like this:

export PHANTOMJS_BIN=/usr/local/bin/phantomjs

As long as you can run "phantomjs" from the command line too and it works, that should probably do it.




回答2:


Install libfontconfig. Assuming you are on ubuntu:

sudo apt-get install libfontconfig

This solved it for me.




回答3:


Upgrade karma-phantomjs-launcher version to 1.0.2 in package.json and reinstall the package.




回答4:


Maybe it helps to somebody. I got the same console messages all of a sudden without no valid reasons, I just stopped grunt and wanted to restart it.

I npm uninstalled karma and reinstalled karma.



来源:https://stackoverflow.com/questions/28876061/phantomjs-cannot-start-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!