Vite manifest not found when registering custom asset and deploying to production

I have a weird issue when trying to deploy to production.

I have a custom asset loaded using
FilamentAsset::register([
    Js::make('echo', Vite::asset('resources/js/echo.js')),
]);

However, during composer's post-autoload-dump the following commands are executed

"@php artisan package:discover --ansi",
"@php artisan filament:assets"

both of which fail because the Vite manifest hasn't been generated yet.

The manifest is generated when I ran
npm run build
but I can't do that because this fails if I haven't installed the composer dependencies yet.

So I'm in this weird catch-22 where the composer step fails because I can't build the Vite manifest, and I can't build the Vite manifest because the composer step fails.

Removing the FillamentAsset::register... code solves the issue but it's obviously not a solution so I wonder if I'm missing something.

I use Forge/Envoyer for the deployments so most steps are vanilla Envoyer stuff. All of it worked untill I wanted to load a custom asset.

The manifest is not commited into the repo BTW. Am I supposed to commit it?
Solution
you can also load the script with a renderhook instead of 'FilamentAsset'
Was this page helpful?