question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"swal is not defined" after migrating from Sweet Alert 1

See original GitHub issue

I was previously using the original Sweet Alert, and things were working fine. Upgraded to SA2 and followed the migration guide. My code:

import swal from "sweetalert2"

swal({
    title: "Are you sure?",
    text: "This cannot be undone.",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Yes.",
    closeOnConfirm: false,
    showLoaderOnConfirm: true
}).then(function() {
    /* do stuff */
})

This results in swal is not defined.

Webpack doesn’t report an error, so it’s not a compilation issue. Do I have to do something else to make this work? Other than switching from callbacks to promises as per the migration guide, nothing else has changed in my code. Using Chrome.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

85reactions
limontecommented, Mar 29, 2017
34reactions
webhackingcommented, Feb 7, 2018
import swal from 'sweetalert2';

window.swal = swal
Read more comments on GitHub >

github_iconTop Results From Across the Web

Sweetalert SWAL is not defined - after NPM install - Laracasts
I have installed sweetalert by the following command: npm install sweetalert --save Now it appears if ... Sweetalert SWAL is not defined -...
Read more >
ReferenceError: "Swal is not defined" - Stack Overflow
I'm working on small project using codeigniter and VueJs and sweet alert javascript library. but i get an error ...
Read more >
SweetAlert2 (Swal is not defined) How to solve? - jQuery Forum
When I click the button, no action is taken. On the "Console" I get the following message: "Uncaught ReferenceError: Swal is not defined"....
Read more >
Guides - SweetAlert
Showing an alert. After importing the files into your application, you can call the swal function (make sure it's called after the DOM...
Read more >
[Solved]-ReferenceError: "Swal is not defined"-Vue.js
Swal (with Capital S) and Swal.fire() is introduced in sweetalert2 version > 7.20.0 . In older versions ( < 7.20.0 ), you should...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found