2
votes

I was trying to publish my new laravel project using Forge+DigitalOcean but I get the error message (We were unable to install a project on your server) due to php artisan optimize command returning Invalid filename provided. error.

So I modified my .env file and set APP_DEBUG to false and tried to run the command locally. I got the following error:

php artisan optimize -v

Generating optimized class loader Compiling common classes [RuntimeException] Invalid filename provided.
Exception trace: () at /home/bubut/Code/TalalAttendance/vendor/classpreloader/classpreloader/src/ClassPreloader.php:105 ClassPreloader\ClassPreloader->getCode() at /home/bubut/Code/TalalAttendance/vendor/laravel/framework/src/Illuminate/Foundation/Console/OptimizeCommand.php:89 Illuminate\Foundation\Console\OptimizeCommand->compileClasses() at /home/bubut/Code/TalalAttendance/vendor/laravel/framework/src/Illuminate/Foundation/Console/OptimizeCommand.php:70 Illuminate\Foundation\Console\OptimizeCommand->fire() at n/a:n/a call_user_func_array() at /home/bubut/Code/TalalAttendance/bootstrap/cache/compiled.php:1138 Illuminate\Container\Container->call() at /home/bubut/Code/TalalAttendance/vendor/laravel/framework/src/Illuminate/Console/Command.php:150 Illuminate\Console\Command->execute() at /home/bubut/Code/TalalAttendance/vendor/symfony/console/Command/Command.php:258 Symfony\Component\Console\Command\Command->run() at /home/bubut/Code/TalalAttendance/vendor/laravel/framework/src/Illuminate/Console/Command.php:136 Illuminate\Console\Command->run() at /home/bubut/Code/TalalAttendance/vendor/symfony/console/Application.php:827 Symfony\Component\Console\Application->doRunCommand() at /home/bubut/Code/TalalAttendance/vendor/symfony/console/Application.php:191 Symfony\Component\Console\Application->doRun() at /home/bubut/Code/TalalAttendance/vendor/symfony/console/Application.php:122 Symfony\Component\Console\Application->run() at /home/bubut/Code/TalalAttendance/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:100 Illuminate\Foundation\Console\Kernel->handle() at /home/bubut/Code/TalalAttendance/artisan:36

3

3 Answers

3
votes

Laravel allows you to specify additional files to be compiled -- generally files that are used on every request in the application.

The file list is specified in /config/compile.php in the files array. If you have specified a file there but it does not exist (or the location is wrong) then artisan will throw that error when trying to compile it.

Same thing happened to me and removing the non-existent file from the list fixed my problem.

2
votes

Same issue toady, and after debugging in Illuminate\Foundation\Console\OptimizeCommand, I found that some symfony components missing in vendor folder, even with composer install/update command for some reason.

Remove contents under vendor folder, then do composer update to see if missing components back. Or git clone whole project and composer update. Note that composer install will check composer.lock, if it existing and components missing there, issue triggered.

0
votes

Note: For additional information

If your files are in a folder inside app folder, this is how you should list them.

'files' => [
'app/your_folder_name/file_a.php',
'app/your_folder_name/file_b.php',
'app/your_folder_name/file_c.php',
]

Hope this helps anyone who one to compile their custom functions.