MorganFreeFarm
MorganFreeFarm

Reputation: 3733

Cannot start SweetAlert2, throw errors?

HTML:

<html>
<head>
    <script
    src="https://code.jquery.com/jquery-3.4.1.min.js"
    integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
    crossorigin="anonymous"></script>
    <script type="module" src="sweetalert2.js"></script>
    <link rel="stylesheet" href="sweetalert2.min.css">
    <script type="module" src="test.js"></script>
</head>
<body>

</body>
</html>

JS:

$( document ).ready(function() {

    import Swal from 'sweetalert2.js'

    Swal.fire({
        title: 'Error!',
        text: 'Do you want to continue',
        type: 'error',
        confirmButtonText: 'Cool'
    })
});

Both files (test.html and test.js) are in same directory!

Errors:

Unexpected identifier at test.js - line 3

TypeError: Cannot set property 'Sweetalert2' of undefined - sweetalert2.js - line 8

SweetAlert2

Upvotes: 0

Views: 1744

Answers (1)

suresh bambhaniya
suresh bambhaniya

Reputation: 1687

here you dont need import Swal from 'sweetalert2.js'

working example

<!DOCTYPE html>
<html>
<head>
<title>sweetalert2</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@8"></script>
<script>
  $(document).ready(function() {
    Swal.fire({
    title: 'Error!',
    text: 'Do you want to continue',
    type: 'error',
    confirmButtonText: 'Cool'
  })
  });

</script>

</body>
</html>

Upvotes: 1

Related Questions