10

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.
Samira kalantari
  • 320
  • 1
  • 2
  • 16

4 Answers4

29

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.

Samira kalantari
  • 320
  • 1
  • 2
  • 16
CUGreen
  • 3,066
  • 2
  • 13
  • 22
  • In this way works but I cannot manage to test with Dusk on Travis CI. Because TravisCI install all the composer packages every time, so if dusk is in "dont-discover" it cannot find it. – Davide Casiraghi Mar 29 '19 at 15:23
6

Look, it does not work because it is configured to work on local and testing environment. I guess that you need to add 'production' (if your production is called 'production in your .env file environment:

AppServiceProvider

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

When installing to production server I just needed to use the --no-dev flag

composer install --no-dev

Good luck!

Adam Kozlowski
  • 5,606
  • 2
  • 32
  • 51
1

If you're experiencing this problem while in a developing environment and accidentally landed here due to the title, you should check that your .env file is set up for development. It should contain the line

APP_ENV=local

Here is an example of how the .env file could look: https://github.com/laravel/laravel/blob/master/.env.example

And here is the Laravel documentation: https://laravel.com/docs/5.7/configuration


Also, in composer.json, laravel/dusk should be listed under require-dev and not require.

Chrisjan
  • 342
  • 2
  • 10
1

Check whether file which named .env contained in the source folder and setup Database user name and password and other settings.

I had the same problem because I have set all the things but forgot to change the .env.example to .env

Thilina Dharmasena
  • 2,243
  • 2
  • 19
  • 27