lucasweaver's avatar

Vite not working on production

I just upgraded to laravel 10 and livewire v3, so had to migrate to vite from mix.

Everything is working fine locally, but in production, @vite(['resources/css/app.css', 'resources/js/app.js']) renders as plain text.

I followed the instructions here: https://laravel.com/docs/10.x/vite#loading-your-scripts-and-styles and here: https://github.com/laravel/vite-plugin/blob/0.x/UPGRADE.md#migrating-from-laravel-mix-to-vite to a "t".

I also did not accidentally commit the "hot" file.

I also had a problem where it won't recognize the namespace change to App\Liveiwre in production, so I'm wondering if I'm having a weird caching issue.

I've cleared all the caches 100 times. My site is hosted on forge.

Any ideas would be much appreciated!!

0 likes
9 replies
LaryAI's avatar
Level 58

It sounds like you're experiencing an issue where the @vite directive is not being processed correctly in your production environment. Here are a few steps you can take to troubleshoot and resolve the issue:

  1. Ensure Vite is Installed and Built Correctly: Make sure that you have run npm install and npm run build in your production environment to install all necessary dependencies and to build your assets.

  2. Check Your Blade Syntax: Verify that the @vite directive is used correctly in your Blade templates. It should look like this:

    @vite(['resources/css/app.css', 'resources/js/app.js'])
    
  3. Verify the Production Environment: Ensure that your application is running in the production environment. You can check the .env file for the APP_ENV variable, which should be set to production.

  4. Clear Blade View Cache: Since you've mentioned clearing caches, make sure you've cleared the Blade view cache specifically with the following command:

    php artisan view:clear
    
  5. Check File Paths: Verify that the paths specified in the @vite directive are correct and that the files exist in your production environment.

  6. Inspect the Compiled Assets: Check the public/build directory to ensure that the compiled assets are present and have the correct permissions.

  7. Check the Network Requests: Open the browser's developer tools and check the network tab to see if there are any failed requests for your CSS or JS files. This can indicate a path or permission issue.

  8. Review the Vite Configuration: Review your vite.config.js file to ensure that it is configured correctly for production. Pay special attention to the base option, which might need to be adjusted depending on your server setup.

  9. Check for Errors in the Console: Look for any errors in the browser console or server logs that might indicate what the issue is.

  10. Namespace Issue: Regarding the namespace change to App\Liveiwre, ensure that you have updated your namespace references everywhere in your application, including in your Livewire components and any place where you might be referencing the old namespace.

  11. Check for Server-Specific Caching: Since your site is hosted on Forge, check if there are any server-level caching mechanisms in place that might be serving stale content.

  12. Forge Deployment Script: Review your Forge deployment script to ensure that it includes the necessary steps for building assets and clearing caches.

If you've gone through all these steps and the issue persists, you might want to provide more specific details about the error messages or behaviors you're seeing, as this can help in diagnosing the problem more accurately.

lucasweaver's avatar

I've obviously been working with ChatGPT for days on this, so sadly Larry's suggestions aren't helpful.

I've also been through stack overflow and others and can't seem to find any fixes.

pk2007's avatar

I am facing the same issue. I have installed the default Laravel 9 which comes preconfigured with vite

1 like
lucasweaver's avatar

@susanb Glad you got it fixed. As you can see in my original post the hotfile wasn't the issue for me. What eventually worked for me was just running composer install and composer update in the Forge command UI. Not sure why it finally changed, but I suspect a caching issue.

Xoshbin's avatar

I'm having same issue @vite generates plain text it's been 48 hours working on it tried every solution nothing worked. Did you guys found any solution please?

DhPandya's avatar

@Xoshbin Have you generated the assets using npm run build ? Please add your Vite file here.

``` code here```

Please or to participate in this conversation.