Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

devley's avatar
Level 2

Livewire on production not loading the variables from the component

Hi! I have an issue with setting up Livewire 3 in my production environment.

I deployed my project with ploi.io to a Ubuntu server. The variable in the first component (and also other components) is not loading from the class to the blade.

class ReviewSection extends Component
{
    public $reviews = [
        [
            'name' => 'Rick van der Loo',
            'rating' => 3,
            'review' => 'De lessen waren flexibel en pasten perfect in mijn drukke schema.',
            'avatar' => 'https://i.pravatar.cc/300?img=4',
        ],
    ];

    public $isMobile = false;

    public function mount(): void
    {
        $agent = new Agent();
        $this->isMobile = $agent->isMobile();
    }

    public function render(): Application|Factory|\Illuminate\Contracts\View\View|View
    {
        return view('livewire.components.review-section')
            ->with('reviews', $this->reviews)
            ->with('isMobile', $this->isMobile);
    }

and in the review-section.blade.php I'm just using the variable $isMobile and it's not defined on production.

Locally there is no issue and I've tried a couple things already.

  • adding @livewireStyles and @livewireScripts (i'm using livewire:layout, so I thought that wasn't needed).
  • New npm build
  • published livewire assets

the issue is clearly that livewire is not being loaded. In console window.Livewire is not loading either).

I'm clueless on what to do next. Am I missing something? Thanks in advance.

0 likes
3 replies
LaryAI's avatar
Level 58

It sounds like you're experiencing an issue where Livewire isn't properly loading in your production environment. Here are some steps you can take to troubleshoot and resolve this issue:

  1. Check for JavaScript Errors:

    • Open your browser's developer console and look for any JavaScript errors. If window.Livewire is not defined, it might indicate that the Livewire scripts are not being loaded correctly.
  2. Verify Asset Compilation:

    • Ensure that your assets are correctly compiled and deployed. Run npm run production to compile your assets for production and make sure the compiled files are correctly uploaded to your server.
  3. Ensure Livewire Scripts and Styles are Loaded:

    • Even if you're using livewire:layout, double-check that @livewireStyles and @livewireScripts are included in your Blade layout file. This ensures that Livewire's JavaScript and CSS are loaded.
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Your App</title>
        @livewireStyles
    </head>
    <body>
        {{ $slot }}
        @livewireScripts
    </body>
    </html>
    
  4. Check for Caching Issues:

    • Clear any cached views and configurations. Run the following commands on your server:
      php artisan config:cache
      php artisan view:clear
      php artisan cache:clear
      
  5. Verify Deployment Configuration:

    • Ensure that your deployment process is correctly copying all necessary files, including the public directory where your compiled assets reside.
  6. Check for Environment Differences:

    • Make sure your production environment is set up similarly to your local environment. Check for differences in PHP versions, server configurations, or any other environment-specific settings.
  7. Inspect Network Requests:

    • Use the Network tab in your browser's developer tools to ensure that all necessary assets are being loaded without errors. Look for 404 errors or other issues that might indicate missing files.
  8. Review Server Logs:

    • Check your server logs for any errors that might provide more insight into what's going wrong.

By following these steps, you should be able to identify and resolve the issue with Livewire not loading properly in your production environment. If the problem persists, consider providing more specific error messages or logs for further assistance.

devley's avatar
Level 2

Problem is solved. The issue was related to having the components in a folder called components. Weirdly enough.

dmjcv91913's avatar

@devley

I am glad you found your solution:

'livewire.components.review-section'

you can always understand how the framework is working if you test the directory structure of your app.

If you change the following in your Livewire component controller 'livewire.review-section'

What other changes would you need to make in your app for your app to function properly. This will help you when you go to publish.

Please or to participate in this conversation.