Laravel Dusk在Windows平台提示不支持TTY模式,测试无法运行
解决Windows下Laravel Dusk运行时"TTY mode is not supported"的问题
嘿,我之前在Windows环境折腾Laravel Dusk的时候也碰到过一模一样的问题,结合你的配置(Windows10 + Wamp + Laravel5.3 + Dusk1.0),给你几个实用的解决办法:
方法1:直接添加--no-tty参数运行
这是最快速的解决方案,不用改任何代码,直接在控制台执行:
php artisan dusk --no-tty
这个参数会告诉Dusk不要尝试启用TTY模式,完美避开Windows平台的限制,测试应该就能正常跑起来了。
方法2:修改Dusk命令的默认配置(持久化方案)
如果不想每次都加参数,可以修改Dusk的命令逻辑。不过直接改vendor目录文件会被Composer更新覆盖,更稳妥的是创建自定义命令继承原DuskCommand:
- 在
app/Console/Commands目录下创建CustomDuskCommand.php:
<?php namespace App\Console\Commands; use Laravel\Dusk\Console\DuskCommand as BaseCommand; class CustomDuskCommand extends BaseCommand { /** * Execute the console command. * * @return int */ public function handle() { if (! $this->hasOption('no-serve')) { $this->call('serve', [ '--no-reload' => true, '--port' => $this->option('port') ?: 8000, '--no-tty' => true, // 新增这一行,强制禁用TTY ]); } return parent::handle(); } }
- 在
app/Providers/AppServiceProvider.php的register方法里注册这个自定义命令:
public function register() { if ($this->app->environment('local', 'testing')) { $this->app->extend('command.dusk', function () { return new \App\Console\Commands\CustomDuskCommand; }); } }
之后直接运行php artisan dusk就可以正常执行测试了。
方法3:使用Windows子系统Linux(WSL)运行
如果你的Windows10版本支持WSL,可以安装Ubuntu等Linux发行版,在WSL环境里配置你的Laravel项目和Dusk,这样就能原生支持TTY模式,完全避开这个问题。不过这个方案需要额外配置WSL环境,适合经常折腾Linux开发工具的同学。
补充说明
为什么会出现这个错误?因为Laravel Dusk默认会尝试启用TTY模式来启动内置开发服务器,但Windows的CMD/PowerShell并不支持TTY终端特性,所以就抛出了这个提示,只要禁用TTY模式就能解决问题。
内容的提问来源于stack exchange,提问作者zarpio
相关产品推荐
相关产品推荐

