Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dmhall0's avatar

Target ... is not instantiable while building ...

I installed the Spatie Laravel Backup package. It works fine on my local machine but when I push to Laravel Forge / Digital Ocean I get the following error message.

Package operations: 3 installs, 0 updates, 0 removals
  - Installing spatie/temporary-directory (1.3.0): Loading from cache
  - Installing spatie/db-dumper (2.21.1): Loading from cache
  - Installing spatie/laravel-backup (6.15.0): Loading from cache
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

In Container.php line 1017:
                                                                               
  Target [Spatie\Backup\Tasks\Cleanup\CleanupStrategy] is not instantiable wh  
  ile building [Spatie\Backup\Commands\CleanupCommand].                        
                                                                               
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

I have tried all other solutions I could find to this problem and still no luck.

Solution Attempt 1: Remove the package: composer remove spatie/laravel-backup clear the cache and config: php artisan cache:clear php artisan config:clear install the package again: composer require spatie/laravel-backup then recache everything: php artisan optimize

Solution Attempt 2: Remove the config.php file located in bootstrap/cache

Doing each of these resulted in the same error. Any other solutions out there? Thanks for the help!

0 likes
3 replies
aurawindsurfing's avatar

@dmhall0

It looks like the installation and auto-discovery is not working as expected.

Things to consider:

  1. Are you using the same version of PHP on both local and remote?
  2. Are you using the same version of package?
  3. Try removing composer cache and vendor folder and install it again.
  4. Check if you are using correct package version vs laravel version: https://github.com/spatie/laravel-backup/releases
  5. Ask here and describe your issue: https://github.com/spatie/laravel-backup/issues

Hope this points you in the right direction!

dmhall0's avatar

To answer your questions:

  1. Yes, same version of php.
  2. Yes, same package version.
  3. I will give this a try.
  4. Yes, using Laravel 7.
  5. I did that yesterday before posting here and someone moved to Discussions without giving a reply. Still waiting there.
benjamintemitope's avatar

In case, anyone is still facing this, remove the config.php file located in bootstrap/cache. If that didn't work, empty bootstrap/cache.

Source: GitHub

Please or to participate in this conversation.