fbpx
  • Win a Fitbit Inspire HR when you move your hosting to us. Competition ends 30 November 2019

Laravel It is unsafe to run Dusk in production error doing composer update

About Running Laravel Dusk in Production

Laravel Dusk is a testing framework and should not be run on a production server. Laravel reads the .env file and then determines is the server is in production or local or testing. If it’s in production, composer update will fail if it detects Laravel Dusk.

Solutions

Here are three possible solutions to the problem:

1. Don’t discover the package in composer.json

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

2. Check which environment exists before loading it

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

For solutions 1 and 2, since Dusk is a dev dependency, you can also do this when deploying:

composer install --no-dev

3. Temporary change from production to local ((Not recommended)

Although this is not recommended it can solve some high pressure situations. Key will be to remember to fix the problem long term.

References

https://medium.com/@taylorotwell/package-auto-discovery-in-laravel-5-5-ea9e3ab20518
https://stackoverflow.com/questions/49622200/how-to-solve-exception-it-is-unsafe-to-run-dusk-in-production-in-laravel-5-5

 

 

Share this article

Share on facebook
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top