laravel-notify
laravel-notify copied to clipboard
Uncaught (in promise) type error
After setting up package really well but my notifications were still not working. I am using Laravel 10 and php 8.2. I am getting an error that just says Uncaught (in promise) TypeError: i is not a function at module.esm.js:1053:28. Anyone with a possible working solution? I am using Inertiajs and Laravel
I'm getting the same error. For me, it conflicts with AlpineJS. It seems like it's related to this issue: https://laracasts.com/discuss/channels/livewire/livewire-modal-freezing-page
The issue doesn't remain when I remove the @notifyJs helper from my layout file.
Notifying does still work after removing it.
I got the same Issue today, the root problem is. The package started a new instance of AlpineJS and replaced the previous AlpineJS instance that was called from app.js. Here 👇🏻
https://github.com/mckenziearts/laravel-notify/blob/fddde15ae2407792f2884e6f9107d49e9e608cbe/resources/js/notify.js#L1-L12
The quick solution is, to remove the @notifyJs line from your layout. Then copy this code
https://github.com/mckenziearts/laravel-notify/blob/fddde15ae2407792f2884e6f9107d49e9e608cbe/resources/js/notify.js#L3-L9
And paste to your main js app.js
Details

For a long-term solution, I think someone should create a PR to add the ability to load Alpine conditionally. Or @mckenziearts can do that.
Hello, @akunbeben, thanks for your prompt response. While the solution you showed me works, I still got one issue where the toast does not show up when it's supposed to. Like I have to refresh the page for the toast to show up which beats the whole purpose of having a toast in the first place. Is this something you have ever come across or it's an issue with my setup?
You can't achieve that by default, using this package. This package only pushes the toast (message) to the sessions and doesn't have a listener that are listening for the toast message.
An easy way, you can use other packages such as Filament/Notifications, etc. The hard way, create a broadcast event and listen to it using laravel echo.
@MotionPhix, another alternative I found was TALL Toasts.
I also struggled with the event not listening, without adding functionality myself to listen to the event.
Hopefully with a newer release of this package, it has a built-in event listener hook.