Why is it that Vue3 Toastify struggles to identify the toast object that they clearly mention we should be using?

Currently, I have integrated a vue3 package known as vue3.toastify for managing my toast notifications.

The guidelines provided in the documentation clearly mention that to modify default transitions globally, the following code snippet must be implemented:

app.use(
  Vue3Toasity,
  {
    transition: toast.TRANSITIONS.FLIP,
    // Available options: toast.TRANSITIONS.BOUNCE, toast.TRANSITIONS.ZOOM, toast.TRANSITIONS.SLIDE
  }, // as ToastContainerOptions
);

Unfortunately, upon implementing this code, the application throws an error message:

app.js:1212 Uncaught ReferenceError: toast is not defined
    at eval (main.js:29:1)
    at ./src/main.js (app.js:294:1)
    at __webpack_require__ (app.js:1209:33)
    at app.js:2389:109
    at __webpack_require__.O (app.js:1255:23)
    at app.js:2390:53
    at app.js:2392:12

I am placing this code within my main.js file:

import { createApp } from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'

import ClickOutside from "./directives/clickOutside.js";
import hapticDirective from "./directives/hapticDirective.js";

import Vue3Toasity from 'vue3-toastify';
import 'vue3-toastify/dist/index.css';

console.log(Vue3Toastify);

createApp(App)
    .directive("haptic", hapticDirective)
    .directive("click-outside", ClickOutside)
    .use(store)
    .use(router)
    .use(
        Vue3Toasity,
        { 
            closeButton: false,
            containerClassName: 'toast-container-class',
            toastClassName: 'toast-class',
            bodyClassName: 'toast-body-class',
            progressClassName: 'progress-bar',
            autoClose: 30000,
            transition: toast.TRANSITIONS.BOUNCE,   // Unfortunately, this does not work :(        
            style: {
              opacity: '1',
              userSelect: 'initial',
            },
        })
    .mount('#app')

In contrast, when I implement it locally within my child component Login.vue, everything works smoothly:

const registerWithGoogle = async () => {
      error.value = null;
      success.value = null;
      const auth = getAuth();
      const provider = new GoogleAuthProvider();
      try {
        const userCredential = await signInWithPopup(auth, provider);
        console.log(userCredential.user);
        await store.dispatch("logInStateCommit", {
          user: userCredential.user,
        });

        success.value = "You're in!";
        router.push("/dashboard");
      } catch (err) {
        handleAuthError(err);
      }
    };

    const handleAuthError = (err) => {
      console.error(err.message);
      switch (err.code) {
        case "auth/invalid-email":
          error.value =
            "The email address provided is not in a valid format. Please enter a valid email address.";
          break;
       
        case "auth/missing-password":
          error.value = "Please type your password";
          break;

        case "auth/unauthorized-domain":
          error.value =
            "You can't login using an authentication provider form this specific domain";
          break;
        default:
          error.value =
            "An unknown error has occurred. Please try again later or contact support for assistance";
          break;
      }
      toast.error(error.value, {
        transition: toast.TRANSITIONS.BOUNCE, // Works perfectly here
      });
    };

If anyone could provide guidance on resolving this issue, it would be greatly appreciated. Thank you in advance.

Answer №1

Issue resolved! I discovered that I had to include the 'toast' module in my main.js file.

import Vue3Toasity, {toast} from 'vue3-toastify';

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Both Google Chrome and Firefox are recognizing the Binance WSS api url as an HTTPS connection

My attempt to execute the code from my Chrome browser was unsuccessful. import io from 'socket.io-client'; const socket = io('wss://stream.binance.com:9443'); socket.on('connect', () => { console.log('binance [so ...

Content that is dynamically generated by a database

I have been working on creating a unique wall feature for my website, inspired by Facebook. My aim is to allow users to submit form data and have it validated before storing it in a database. Additionally, I want this stored data to be displayed in a desig ...

An error occurred when attempting to search for 'length' using the 'in' operator in the context of the Datatables plugin and jQuery 1.11.3

I implemented the jQuery Datatables plugin in my tables for pagination, sorting, and searching functionalities. However, I am facing issues where the elements are not working properly, and the pagination occasionally fails to display. The Chrome console is ...

Tips for setting a default checked radio button in Vuejs

Upon page load, the radio button status should initially be checked. Then, when the radio button is changed, a div below it should hide and show accordingly. I have attempted to write the code for this functionality, but unfortunately it is not working a ...

Retrieve geographical coordinates from image metadata using JavaScript

Seeking help with extracting the GPS Exif tag from images using NodeJS. The data is currently structured as follows: { "gps": { "GPSTimeStamp": [2147483647, 76, 41], "GPSLongitude": [76, 41, 56.622], "GPSLatitude": [30, 43, 8 ...

Under specific circumstances, it is not possible to reset a property in vue.js

In Vue.js, I have developed a 'mini-game' that allows players to 'fight'. After someone 'dies', the game declares the winner and prompts if you want to play again. However, I am facing an issue where resetting the health of bo ...

Implementing a jQuery change event to filter a specific table is resulting in filtering every table displayed on the page

I have implemented a change event to filter a table on my webpage, but I am noticing that it is affecting every table on the page instead of just the intended one. Below is the code snippet: <script> $('#inputFilter').change(function() { ...

Implementing a loading animation effect using AJAX that requires a loop delay and sleep functionality

My jquery ui dialog is loaded via ajax with a partial view from the server. Initially, the dialog opens as a dialog-ajax-loader and then animates/grows to fit the content once the call returns. The issue arises when the dialog content gets cached or the a ...

How can you transfer data from a jQuery function to a designated div element?

I'm struggling to transfer data from a function to a specific div, but I can't seem to make it work. I'm in the process of creating a gallery viewer and all I want is to pass the counter variable, which I use to display images, and the total ...

Loading two scripts in sequence, the first utilizing the "src" attribute while the second is an inline script

The HTML code below shows two script elements being added to the body of a webpage. <html> <body> <script> const first = document.createElement("script"); first.setAttribute("src", "./remote.js"); first.async = false; const second = doc ...

The page keeps refreshing repeatedly

Can someone help me troubleshoot this url modification script? var currentPath = window.location.href currentPath=currentPath.replace(/&amp;/g, "&"); window.location.href=path; It seems like the page keeps reloading endlessly... Any sugg ...

Place the token within the Nuxt auth-module

Working on a project using the Nuxt auth-module. The Login API response is structured like this: data:{ data:{ user:{ bio: null, createdAt: "2021-06-29T12:28:42.442Z", email: "<a href="/cdn- ...

Where can the Path be found for Json inside App Phonegap?

Having some trouble with my Phonegap App! Everything seems to be working fine when I test it in my browser. However, once I compile it into an APK and install it on my phone, it's unable to find the JSON data. I'm a beginner in programming and a ...

Is it possible to save any additions made to the DOM using JavaScript into local storage, so that it can be retrieved even after the page is reloaded?

Let's consider a scenario for testing purposes: you have a function that appends <li> elements inside an <ol> container, and you want to retain all the list items added. Is there a way to store them in Local Storage (or any other local sto ...

What is the correct process for submitting an HTML form following the loading of asynchronous data?

I've been searching high and low, but I can't seem to find the solution to my problem. I've scoured search engines and Stack Overflow with no luck. My dilemma is this: How can I trigger the submission of an HTML form only after asynchronous ...

I am selecting specific items from a list to display only 4 on my webpage

I am trying to display items from a list but I only want to show 4 out of the 5 available items. Additionally, whenever a new item is added, I want it to appear first on the list, with the older items following behind while excluding the fifth item. Despi ...

Splitting code efficiently using TypeScript and Webpack

Exploring the potential of webpack's code splitting feature to create separate bundles for my TypeScript app has been a priority. After scouring the web for solutions, I stumbled upon a possible lead here: https://github.com/TypeStrong/ts-loader/blob/ ...

What is preventing me from being able to manipulate the data retrieved from this ajax request?

I've been attempting to make an ajax call to my json server on localhost:3000 in order to retrieve an object that I can manipulate and display on a webpage. However, no matter what I try, I just can't seem to console log the (data) so that I can ...

What are the steps for testing React components when they are wrapped by ThemeProvider/withStyle?

Is there a way to properly test a component that is wrapped with withStyle, as it seems the theme object does not pass through the component. Any suggestions on best practices for achieving this? I am considering using createShallow() and dive() methods t ...

Modifying the name of a file upload in AngularJS

Does anyone know a way to dynamically change the file name in AngularJS? <input type="file" onchange="angular.element(this).scope().filename(this)"> In the filename method, I am attempting to change the file name but the value is not updating. How ...