Update: it appears our server updated, so our opcache version was incorrect and seemed to have caused the issue somehow.
"It is unsafe to run Dusk in production." error when trying to deploy
For some reason when running the following deploy script, my app all of sudden is trying to run dusk on production deployment, and throwing an error. I do have dusk installed and have written some tests, but that was over a month ago, and i've made 100+ commits and many deployments without issue.
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postInstall
> php artisan optimize
[Exception]
It is unsafe to run Dusk in production.
Script php artisan optimize handling the post-install-cmd event returned with error code 1
Here is my deploy Script:
# stop script on error signal
set -e
# remove old deployment folders
if [ -d "/home/forge/deploy" ]; then
rm -R /home/forge/deploy
fi
if [ -d "/home/forge/backup" ]; then
rm -R /home/forge/backup
fi
cp -R /home/forge/app-name.com /home/forge/deploy
# Update
cd /home/forge/deploy
git stash
git pull origin production
composer install --no-interaction --no-dev --prefer-dist
yarn
npm run production
# Reset opcache
echo "" | sudo -S service php7.0-fpm reload
# Switch (downtime for microseconds)
mv /home/forge/app-name.com /home/forge/backup
mv /home/forge/deploy /home/forge/app-name.com
# Cache All The Things for Performance
cd /home/forge/app-name.com
php artisan view:clear
php artisan route:cache
php artisan config:cache
In my app service provider:
public function register()
{
// Dusk, if env is appropriate
if ($this->app->environment('local', 'testing')) {
$this->app->register(DuskServiceProvider::class);
}
}
So then I went through and removed every instance of Dusk in my app, and now the deploy is failing with the following error:
> php artisan optimize
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Laravel\Dusk\DuskServiceProvider' not found
Script php artisan optimize handling the post-install-cmd event returned with error code 1
We have tried clearing cache, opcache, all kinds of things to no avail. Any ideas?
For anyone scratching their head upgrading from 5.4 to 5.5 and getting this error, it was solved for us by adding the dont-discover portion to our composer.json file as detailed here:
https://medium.com/@taylorotwell/package-auto-discovery-in-laravel-5-5-ea9e3ab20518
Sounds like the docs need to be updated, or at least made a little more obvious.
Also, it should be noted, that we kept the same service provider registration as documented in the installation instructions for dusk in 5.4
Please or to participate in this conversation.