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
However, during composer's
post-autoload-dump
the following commands are executed
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?18 Replies
fails too for the same reason
Oh FFS... This is because of
which doesn't exist until I run
composer install
but I can't run composer install until I run npm run build
... Fucking great!so, just remove the 'filament:assets' command from your composer scripts, then call it after 'npm run build' in your deploy script.
It's not just the fillament:assets that fails. package:discover and filament:upgrade also fail
And by 'fail' I mean I get the same
ViteManifestNotFoundException
exception
So I need to find an alternative way to load an Alpine plugin so I can replace this in my app.js
floating ui is already included with filament though.
Yeah but I think we need it in other non-filament pages
and we might need other plugins anyway
then load it asset in your non-filament pages with the normal blade '@vite' directive.
Sorry, what do you mean? This is loaded into the custom layout file like this
Is there another/better way?
(most of it is vanilla stuff from the livewire docs)
maybe i'm getting confused, you started out saying it was an issue with 'FilamentAsset::register' for echo.js now its an issue with 'app.js'.
Yeah sorry about that. The issue started when I loaded a custom asset using
FilamentAsset::register
which needs the (AFAIK) the vite manifest to exist so it can find the asset.
However, during deployment, NPM (install + build)
are executed after composer install
. But I have code in my app.js that needs some files from the vendor
folder to work
not sure if it makes sense? It's a cyclic dependency of sorts
I need both the code in app.js
and the ability to load fillament assets, but I can't have bothyou don't need any of that in your composer scripts
let the server run them instead of composer.
yeah I guess that's the only solution. It'll make local development a bit more annoying since we'll have to remember all those steps when installing/upgrading locally but what can you do...¯\_(ツ)_/¯
Solution
you can also load the script with a renderhook instead of 'FilamentAsset'
Hmm didn't think about that. I'll look into it . Are there any drawbacks to it? (eg if I use the
PanelsRenderHook::SCRIPTS_AFTER
hook)no drawback
with Vite, i would probably recommend it.
This seems to have worke, thank you very much 🙇♂️
FWIW, this is what I did
@ChesterS @awcodes I tried this in my app, and it worked on my local but in prod, I received
Unable to locate file in Vite manifest: resources/js/plugins/scrollable.js
I used this oneHave you added it to your
vite.config.js
and ran npm run build
?This is the way! Thanks @awcodes