phplaravellaravel-modules

Service provider not loaded for one module (Laravel Modules)


I ran into a weird problem. I'm using Nwidart Laravel Modules package. I have got many modules and everything works as expected: service providers register routes for each module etc. But suddenly, I lost contact with one module - all my endpoints are not registered - I see only 404 error page. At first, I checked php artisan route:list - missing API routes are there. Then I checked php artisan module:list - the missing module is loaded and enabled. Next step: check module.json file in module directory: looks ok, module service provider exists in providers array. I do some debugging, and I found that this provider is not loaded anymore. I am trying to figure out what's wrong here, but I'm out of ideas.

Update:

After I run php artisan route:cache command, missing routes are now available.


Solution

  • I finally figured it out. I will describe my case here; I hope it will help someone in the future. Two things were responsible for my issue: bootstrap/cache and DeferrableProvider. At some point, I used DeferrableProvider for my module but I even didn't know it that is not working, because configuration for this module was cached as manifest file inside bootstrap/cache directory (XYZ_module.php). The valid configuration was always loaded until I've done composer update and cleared caches. Since then, the wrong configuration is preserved in cache causing module fault. I had to remove DeferrableProvider interface from provider class to fix it ($defer and provides method also). The next step is to clear the cache/config etc. and I'm back to business!

    Update: clearing cache/config may not remove modules manifest files from bootstrap/cache directory. In this case, files need to be deleted manually.