在我的 Ubuntu VM 上的项目上从本地安装运行 Karma 时,Karma 将无法运行,因为 PhantomJS 无法启动。
版本信息:
相同的脚本在我的 Mac OS 上运行得很好(我在运行之前删除了 karma 的全局安装,它仍然有效)。
在 Ubuntu 上,如果我直接通过 ./node_modules/phantomjs/bin/phantomjs 启动 phantomjs,它启动得很好。
这是 shell 输出:
> ./node_modules/karma/bin/karma start test/karma.conf.js
DEBUG [config]: autoWatch set to false, because of singleRun
DEBUG [plugin]: Loading karma-* from /srv/detectiveui/node_modules
DEBUG [plugin]: Loading plugin /srv/detectiveui/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /srv/detectiveui/node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin /srv/detectiveui/node_modules/karma-spec-reporter.
INFO [karma]: Karma v0.12.31 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
DEBUG [temp-dir]: Creating temp dir at /tmp/karma-42625347
DEBUG [launcher]: /srv/detectiveui/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /tmp/karma-42625347/capture.js
DEBUG [launcher]: Process PhantomJS exited with code 2
ERROR [launcher]: Cannot start PhantomJS
DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-42625347
INFO [launcher]: Trying to start PhantomJS again (1/2).
DEBUG [launcher]: Restarting PhantomJS
DEBUG [temp-dir]: Creating temp dir at /tmp/karma-42625347
DEBUG [launcher]: /srv/detectiveui/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /tmp/karma-42625347/capture.js /tmp/karma-42625347/capture.js
DEBUG [watcher]: Resolved files:
#...List of my files here that look correct...
DEBUG [launcher]: Process PhantomJS exited with code 2
ERROR [launcher]: Cannot start PhantomJS
DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-42625347
INFO [launcher]: Trying to start PhantomJS again (2/2).
DEBUG [launcher]: Restarting PhantomJS
DEBUG [temp-dir]: Creating temp dir at /tmp/karma-42625347
DEBUG [launcher]: /srv/detectiveui/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /tmp/karma-42625347/capture.js /tmp/karma-42625347/capture.js /tmp/karma-42625347/capture.js
DEBUG [launcher]: Process PhantomJS exited with code 2
ERROR [launcher]: Cannot start PhantomJS
DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-42625347
ERROR [launcher]: PhantomJS failed 2 times (cannot start). Giving up.
DEBUG [karma]: Run complete, exiting.
DEBUG [launcher]: Disconnecting all browsers
我似乎也可以在端口 9876 上手动启动节点服务器,所以这也可能不是问题。
任何帮助将不胜感激。谢谢!
- - 更新
我创建了一个新的 Ubuntu 环境并再次测试相同的东西并得到相同的错误。
最佳答案
我遇到了同样的问题,我将 package.json 文件中的 karma-phantomjs-launcher 更改为“^1.0.0”。
更改后,Phantomjs 开始工作
关于phantomjs - 在本地运行 karma 时,phantomjs 无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29036510/