vincent15000's avatar

$this->laravel is null after packages upgrade

Hello,

I wanted to upgrade Pest from v3 to v4.

So I have remove both pest packages, then reinstalled them.

"pestphp/pest": "^3.8",
"pestphp/pest-plugin-laravel": "^3.8",

And now I get this error while running composer or artisan commands.

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Error 

  Call to a member function make() on null

  at vendor/laravel/framework/src/Illuminate/Console/Command.php:171
    167▕      */
    168▕     #[\Override]
    169▕     public function run(InputInterface $input, OutputInterface $output): int
    170▕     {
  ➜ 171▕         $this->output = $output instanceof OutputStyle ? $output : $this->laravel->make(
    172▕             OutputStyle::class, ['input' => $input, 'output' => $output]
    173▕         );
    174▕ 
    175▕         $this->components = $this->laravel->make(Factory::class, ['output' => $this->output]);

      +5 vendor frames 

  6   artisan:16
      Illuminate\Foundation\Application::handleCommand()

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

What do you suggest me to do ?

Thanks for your help.

V

0 likes
2 replies
vincent15000's avatar
vincent15000
OP
Best Answer
Level 63

The problem is solved.

I have had to clear the bootstrap cache and to add --no-scripts to the commands to have to working.

Then I have upgraded all packages.

And it works fine now.

LaryAI's avatar
Level 58

The error you're seeing:

Call to a member function make() on null
at vendor/laravel/framework/src/Illuminate/Console/Command.php:171

means that the $this->laravel property (the application container) is null when certain artisan or composer events run. This often happens when:

  • There is a mismatch between package versions (Pest, Laravel, per-package plugins).
  • Package caches or generated files are stale after an upgrade.
  • A service provider or one of your custom package providers expects things to be "booted" in an installation event when, in fact, only a subset is being loaded.

Here's what you should try:

1. Check Compatibility

First, make sure the Pest versions you installed are compatible with your Laravel version:

  • Pest v4 requires Laravel 10+.
  • Check your composer.json for Laravel version. For Laravel 9 or earlier, you need to stay with Pest v3.

If your Laravel version is below what's required for Pest v4, downgrade Pest:

composer require pestphp/pest:^3.0 pestphp/pest-plugin-laravel:^3.0 --dev

2. Remove Vendor and Bootstrap Cache

After changing versions (especially after upgrading/downgrading), delete cached files:

rm -rf vendor/
rm -rf bootstrap/cache/*
composer install

3. Clear Config and Autoload Caches

Cached config or route files can cause these issues:

php artisan config:clear
php artisan cache:clear
php artisan route:clear
composer dump-autoload

If you can't run artisan commands due to this error, focus on removing cached files manually (bootstrap/cache/*).

4. Check for Local Changes to Command Code

If you have overridden any artisan commands in your app or in a local package, double-check that you're calling parent::__construct() and not setting $this->laravel manually.

5. Re-install Pest

Double check your required version. This is the correct approach for Laravel 10+:

composer require pestphp/pest:^4.0 pestphp/pest-plugin-laravel:^4.0 --dev

If on Laravel 9 or older:

composer require pestphp/pest:^3.8 pestphp/pest-plugin-laravel:^3.8 --dev

6. Review Service Providers

Try commenting out recently added or custom service providers in your config/app.php to see if the error goes away. You might have a package that's not compatible with your Laravel or Pest version.


Summary of Steps:

  1. Verify Pest/Laravel compatibility.
  2. Remove vendor and cached files, reinstall dependencies.
  3. Clear bootstrap/cache manually if you can't run artisan.
  4. Double-check for custom command or provider issues.
  5. Use correct versions for your Laravel installation.

If you still have issues, share your exact Laravel version and your require/require-dev sections from composer.json for further help!

Please or to participate in this conversation.