skip to Main Content

I am creating a laravel package for production and removing the composer.json and composer. lock once the dependencies are installed. But when I ran any artisan command I get the below error

In Application.php line 1399:
  file_get_contents(/var/www/project_dir/composer.json): Failed to open stream
  : No such file or directory

I am excluding the composer.json from the production environment as the autoloading is done through vendor/autoload.php.

I was doing the same thing previously as well but not sure the issue appeared suddenly when I am deploying the new release.

2

Answers


  1. Chosen as BEST ANSWER

    After investigating the issue I have found that the issue is causing due to

    $this->load(__DIR__.'/Commands'); code called in AppConsoleKernel class in commands() function.

    Basically, we have registered the console commands using php artisan make:command, and it created the file inside the commands directory which is fine. But the load method from vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php try to get the application namespace that fails due to a missing composer.json file.

    So, to handle this I have removed the $this->load(__DIR__.'/Commands'); line from commands() function inside the AppConsoleKernel class and registered the commands manually using $commands property within AppConsoleKernel class.

    https://laravel.com/docs/8.x/artisan#registering-commands


  2. Laravel’s class IlluminateFoundationApplication loads the root application namespace from your composer.json. This is nothing new, I can find such code even in Laravel v6 from 2015.

    If your code was working well in any prior version of Laravel without having a composer.json deployed, but is no longer, you should check what has changed in your application

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search