2

I am working on a legacy Laravel 6 app which is isolated from the rest of the system without internet connection, and when I try to run composer dump-autoload I get:

In ProviderRepository.php line 208: Class 'Facade\Ignition\IgnitionServiceProvider' not found

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

So I can't do what's described in this post: Laravel with App Engine Standard Class 'Facade\Ignition\IgnitionServiceProvider' not found

Update #1: I added the missing class to the dont-discover array in composer.json, then it showed another class missing, so I started adding them one-by-one. Apparently the following 3 packages are "missing" (even though their files are there):

"facade/ignition", "laravel/ui", "nunomaduro/collision".

When added all these 3 to the dont-discover array, I was successfully able to run composer dump-autoload:

"extra": {
    "laravel": {
        "dont-discover": ["facade/ignition", "laravel/ui", "nunomaduro/collision"]
    }
}

But still, I want to know if I can fix the issue with these 3 packages

Can I fix it without internet connection? Anything I can try to do manually?

Update #2:

I saw a comment on another post here suggesting moving the packages from require-dev to require. I did it, and it worked!

https://stackoverflow.com/a/59369455/18178584

In the same post, someone suggested it might be related to a bug when updating from composer 1.x to 2.x:

https://stackoverflow.com/a/67847239/18178584

But since I don't know exactly what happened here, which one of the above can be the cause? And, since the first solution solved it for me, is it safe to leave these 3 packages in require instead of require-dev?

pileup
  • 1
  • 2
  • 18
  • 45
  • 1
    Well, composer definitely requires internet, unless you build a local cache and direct composer to your cache. And how does this setup work running a Laravel application that „runs“ without an internet connection? – dbf Jan 29 '23 at 08:39
  • Until recently we had internet connection so we could use it normally, but then they decided to isolate certain servers from the outside world for security reasons, so we are left with what's been working till now. Do you think it's possible to fix the Class not found issue without internet? Because it's weird, all the files are there and it's also seem to be correct in `composer/autoload_classmap.php` (the correct path of the seemingly missing file) – pileup Jan 29 '23 at 08:43
  • 1
    Oh great, no internet means security, wow :) Well yes you can do a local installation of composer and move the vendor directory to the server or just add the missing files/directories in the directory of vendor. But if this secured server has a LAN connection, they really failed to convince me that it has been secured by dropping internet. – dbf Jan 29 '23 at 09:44
  • 1
    Are you sure the files are there? It should be in `vendor/spatie/laravel-ignition/src/IgnitionServiceProvider.php` double check to see if the file is indeed there. You might need to install them somewhere with internet and copy them over. Worse case you can host a [private Packagist](https://packagist.com/) in the machine without internet, though you might need internet to initialise that setup, or you can host the private Packagist in another networked machine that does have internet access and use that as the main repository source. – apokryfos Jan 29 '23 at 09:48
  • 2
    Uhm a local build would work if the OS are the same, like building a composer build with windows and push it to a Linux server might cause some problems. – dbf Jan 29 '23 at 09:50
  • @apokryfos the IgnitionServiceProvider.php file for me is in `vendor/facade/ignition/src`. Could it be different for different Laravel versions? dbf I know but it's not me who did that haha, and there is no LAN connection, it's completely isolated. At first I also thought about private-packagist, or even better - Satis, which doesn't need any external internet, but things move slowly here – pileup Jan 29 '23 at 10:40
  • 1
    Yes I'm using Laravel 9 and that means I had to switch to spatie/laravel-ignition at some point. Your path seems correct. If the file is in there then double check the `vendor/composer/autoload_psr4.php` file that it registers the path correctly (now that you got the dump-autoload to work). It should look something like: `'Facade\\Ignition\\' => array($vendorDir . '/facade/ignition/src'),`. – apokryfos Jan 29 '23 at 13:20
  • @apokryfos it's weird but it's not there at all even after successfully running the `dump-autoload` command. I even tried to manually add it then run the command (after reverting the code to where it wasn't working) but still not working. So how come the command works if it's not there when moving these packages to`require`? So weird – pileup Jan 30 '23 at 10:01
  • 1
    Since you are presumably installing these at a different machine with internet and then moving them, just double check the composer versions match. – apokryfos Jan 30 '23 at 10:10
  • My bad, it's actually is there when the command is run successfully(after moving from `require-dev` to `require`!), exactly at the path you wrote. I just wonder why it was in `require-dev` in the first place then if it doesn't work like that – pileup Jan 30 '23 at 10:11

1 Answers1

1

Try to refresh your Laravel project, like:

composer run refresh

But for that to work, you first need to implement refresh script in composer.json file, like:

{

    // ...

    "scripts": {
        "refresh": [
            "@composer dump-autoload --no-scripts",
            "@php artisan config:clear",
            "@composer run post-autoload-dump --verbose",
            "@php artisan cache:clear",
            "@php artisan clear-compiled",
            "@php artisan view:clear",
            "@php artisan route:clear"
        ],

        // ...

    }
}

Also, as mentioned in comments, ensure important packages are in require section of composer.json (instead of require-dev).

Only unit-test and/or lint purpose packages should be in require-dev.

Details

Normally composer dump-autoload is enough, but sometimes post-autoload-dump uses cached class, hence php artisan config:clear needs to run first, but "config:clear" may crash if dump-autoload is not done yet.

Solution? Like above, use --no-scripts and trigger post-autoload-dump later manually ;-)

(Well not "manually", I do it all automatically, but you get the idea.)

Top-Master
  • 7,611
  • 5
  • 39
  • 71
  • Thank you! indeed `composer dump-autoload --no-scripts` runs successfully, but then I get the same error `In ProviderRepository.php line 208: Class 'Facade\Ignition\IgnitionServiceProvider' not found` when it tries to run `php artisan config:clear`. Do you think that.. somewhere it really does try to look for another file or there still is some issue with the cache? – pileup Jan 29 '23 at 14:18
  • Update: there seem to have been a bug when updating from composr 1.x to 2.x: https://stackoverflow.com/a/67847239/18178584, could that be the issue? But then again, all the solutions require internet connection - unless it can be done differently – pileup Jan 29 '23 at 14:28
  • Another update (also added the information to the post): it worked after moving those packages that are showing up as missing to `require` instead of `require-dev`, but I have no idea why. – pileup Jan 29 '23 at 14:39
  • 1
    @B.DLiroy `require-dev` is ignored by `composer install`, unless it's `require-dev` section of the root `composer.json` file, check parent folders (maybe there is another `composer.json` file). – Top-Master Jan 29 '23 at 15:03
  • 1
    @B.DLiroy However, if `php artisan ...` commands fail without those packages, then they should always be in `require` (and only unit-test and/or lint purpose packages should be in `require-dev`). – Top-Master Jan 29 '23 at 15:40