mhmiton / laravel-modules-livewire

Using Laravel Livewire in Laravel Modules package with automatically registered livewire components for every modules.
MIT License
184 stars 35 forks source link

Issue with Namespace in laravel-modules and laravel-modules-livewire Packages - Unable to find component: [blog::index] #46

Open solomon-ochepa opened 5 months ago

solomon-ochepa commented 5 months ago

Description:

For the past two weeks, my team and I have been grappling with an issue stemming from the upgrade to Laravel version 10 and Laravel-modules version 10. Initially, we encountered difficulties locating modules, resulting in numerous "routes not found" errors within our module ecosystem. Subsequently, we began experiencing issues with Livewire components not being found. Our application functions smoothly on local machines, but once we mount the volume to a Docker image container, errors such as "Unable to find component: [blog::index]" arise.

Upon attempting to create a Livewire component using the laravel-modules-livewire package within the Docker container, we encountered a peculiar scenario. While the view files were found to already exist, the associated class was missing. Upon re-executing the artisan command to create the component, both the view and class were reported to exist. Further investigation revealed the creation of a new folder labelled "App/" alongside the existing "app/" directory - a case-sensitive path, caused by namespace.

The root cause of this issue lies in the configuration of the Laravel module Livewire package, which utilizes the namespace "App/Livewire". However, due to the mismatch between the existing "app/Livewire" path and the "App/Livewire" namespace, the system throws errors indicating that the component is not found.

Solution:

  1. Update Namespace: One solution involves modifying the namespace to remove the "app/" fragment, resulting in a namespace structure like "Blog/Livewire", instead of "Blog/App/Livewire". While this provides a quick fix, it is not a sustainable solution and may lead to recurring issues in the future.
  2. Include "app/" in Namespace (Lowercase): Another approach entails retaining the "app/" fragment in the namespace but converting it to lowercase. However, this practice is suboptimal and was previously utilized in the laravel-modules package until version 11, which opted for the first solution mentioned above.
  3. Utilize composer-merge-plugin: The most appropriate solution involves mapping the "app/" path to "App/" using the wikimedia/composer-merge-plugin package. This approach ensures compatibility and adherence to naming conventions across different environments.

Additional Notes:

@dcblogdev Your attention to this matter is greatly appreciated.

Thank you.

Issue on laravel-modules:

https://github.com/nWidart/laravel-modules/issues/1819

Ref:

https://github.com/nWidart/laravel-modules/pull/1758

42

mhmiton commented 5 months ago

@solomon-ochepa Could you try with laravel-modules-livewire version 2.3?

solomon-ochepa commented 5 months ago

@solomon-ochepa Could you try with laravel-modules-livewire version 2.3?

I'll try that, sir. Thank you.