Uncaught TypeError: Cannot read property 'then' of undefined using Sweet Alert
<p>I am using <a href="http://limonte.github.io/sweetalert2/" rel="noreferrer">SweetAlert2</a> and I am getting the following error</p>

<blockquote>
  <p>Uncaught TypeError: Cannot read property 'then' of undefined</p>
</blockquote>

<p>When I use the exact same code as suggested in SweetAlert page.</p>

<pre><code>swal({
title: 'Are you sure?',
  text: "You won't be able to revert this!",
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes, delete it!',
  cancelButtonText: 'No, cancel!',
  confirmButtonClass: 'btn btn-success',
  cancelButtonClass: 'btn btn-danger',
  buttonsStyling: false,
  closeOnConfirm: false,
  closeOnCancel: false
}).then(function(isConfirm) {
  if (isConfirm === true) {
    swal(
      'Deleted!',
      'Your file has been deleted.',
      'success'
    );
  } else if (isConfirm === false) {
    swal(
      'Cancelled',
      'Your imaginary file is safe :)',
      'error'
    );
  } else {
    // Esc, close button or outside click
    // isConfirm is undefined
  }
})
</code></pre>

<p>I have the code at the end of the page. I am using it in a Ruby on Rails app. I have tried returning a value as suggested in other posts, but it does not fix the problem</p>