How to solve Exception It is unsafe to run Dusk in production in laravel 5.5?

Samira kalantari picture Samira kalantari · Apr 3, 2018 · Viewed 14.5k times · Source

I upgrated my project from laravel 5.4 to laravel 5.5 ,

I dont have any problem in local env but in server i get this exception ,

I searched a lot and i know this issue may be duplicated but no solutions solved my problem!

How can i not registering dusk when environment is production?

i wrote this code in AppServiceProvider.php :

public function register()
{
    // Dusk, if env is appropriate
    if ($this->app->environment('local', 'testing')) {
        $this->app->register(DuskServiceProvider::class);
    }
}

but it seems not working. can anyone help?

EDITED : my composer.json file:

 "require-dev": {
    "filp/whoops": "~2.0",
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "1.*",
    "phpunit/phpunit": "^7.0.3",
    "symfony/css-selector": "4.0.*",
    "symfony/dom-crawler": "4.0.0",
    "barryvdh/laravel-ide-helper": "^2.4",
    "laravel/dusk": "^2.0"
  },

The Exception is :

Exception
It is unsafe to run Dusk in production.

Answer

CUGreen picture CUGreen · Apr 3, 2018

In Laravel 5.5, packages are automatically discovered and loaded so you will probably need to tell it not to load dusk.

One way is to add this to your composer.json

"extra": {
    "laravel": {
        "dont-discover": [
            "laravel/dusk"
        ]
    }
},

Also, you can add it to your dev dependencies and when you deploy in production, use:

composer install --no-dev

Taylor wrote an article about it here.