Sweetalert2: Uncaught Typeerror: Failed to resolve module specifier "Vue-sweetalert2.js"

Asked

Viewed 432 times

0

I’m trying to use swal2 in Vue, but with this import I’m getting the error

Uncaught Typeerror: Failed to resolve module specifier "Vue-sweetalert2.js". Relative References must start with either "/", ". /", or "../".

I’m importing by following the footsteps of this link: https://www.npmjs.com/package/vue-sweetalert2

import Vuesweetalert2 from 'Vue-sweetalert2.js'
Vue.use(Vuesweetalert2);

I’ve tried using . /Vue-sweetalert2.js and even specify the path, but it doesn’t solve. When I try to specify the path I get the error (Not Found).


import VueSweetalert2 from 'vue-sweetalert2.js'
Vue.use(VueSweetalert2)

new Vue({
    el: '#signin-form',
    components: {

    },
    data: {
        email: "",
        password: ""
    },
    mounted() {

    },
    methods: {
        showAlert(){
            this.$swal('Olá, você logou com sucesso!');
        },

        processForm(){
            axios({
                method: "POST",
                "url": "http://192.168.0.138:8000/api/loginCandidate",
                data: {"email": this.email, "password": this.password},
            }).then(result => {  
                if(result.data.result){
                    var candidate = result.data.candidate;
                    var token = Object.values(result.data.token);
                    var keys = Object.keys(candidate);

                    localStorage.setItem("token", token);
                    for(var i = 0; i  {
                console.error(error);
            });
       },
    }
})

Additional import or component required?

  • Add in main.js import VueSweetalert2 from 'vue-sweetalert2.js'
Vue.use(VueSweetalert2)

  • There in the documentation in the first part of the use, already has showing this information!

  • Already set..... import privateProps from'.. /privateProps' import Vue from'.. /Vue' import Vuesweetalert2 from'.. /Vue-sweetalert2' Vue.use(Vuesweetalert2)

  • Did it work? Your path is right?

  • The error continues, the path is correct. In this case I am using import inside the _main.js folder of sweetalert2, as it is in the link. I tried to throw the way too.

  • npm i tentoou?

  • I tried : .....

Show 2 more comments

1 answer

1

Friend, to use after import you can do so.

import VueSweetalert2 from 'vue-sweetalert2.js'    
const swal = require('sweetalert2');

Within the methods

 showAlert(){
    swal.fire({
        type: 'warning',
        title: '...Ops!',
        text: 'agora vai funcionar',
        confirmButtonText: 'Voltar',
        showConfirmButton: true
    });
},

Browser other questions tagged

You are not signed in. Login or sign up in order to post.