I'm encountering an issue with a Nuxt 3 client-side plugin.
The documentation for Nuxt 3 plugins states:
Nuxt will automatically read the files in your plugins directory and load them. You can use .server or .client suffix in the file name to load a plugin only on the server or client side.
I've included a plugin named "toaster.client.ts" which utilizes a Vue Toast Notification package with methods like "info", "success", etc. Here's how I implement it on my pages:
const { $toast } = useNuxtApp(); $toast.success('It works');
However, upon refreshing the page, I encounter this error:
Cannot read properties of undefined (reading 'success')
To resolve this, I have to perform the following check:
if(process.client){ $toast.success('You did it!'); }
How can I address this issue? I am using Nuxt 3 with Composition API (setup) and Typescript.