laravel-notify icon indicating copy to clipboard operation
laravel-notify copied to clipboard

Uncaught (in promise) type error

Open MotionPhix opened this issue 2 years ago • 5 comments

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

MotionPhix avatar Apr 11 '23 01:04 MotionPhix

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.

GamendeBrian avatar Apr 11 '23 08:04 GamendeBrian

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

code

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.

akunbeben avatar Apr 14 '23 09:04 akunbeben

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?

MotionPhix avatar Apr 15 '23 15:04 MotionPhix

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.

akunbeben avatar Apr 15 '23 18:04 akunbeben

@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.

GamendeBrian avatar Apr 15 '23 21:04 GamendeBrian