I struggle to make a very simple commonJS usage:
const Swal = require('sweetalert2');
Swal.fire('Hello world!');
What's wrong with it?
if I run the code, nothing happens, no error it thrown either.
I struggle to make a very simple commonJS usage:
const Swal = require('sweetalert2');
Swal.fire('Hello world!');
What's wrong with it?
if I run the code, nothing happens, no error it thrown either.
You cannot use require()
on browser/client-side JavaScript.
You need to grab SweetAlert2 from jsdelivr CDN by adding the following in your index.html
<script src="//cdn.jsdelivr.net/npm/sweetalert2@10"></script>
Then you can just run your JS
Swal.fire('Hello world!');
CodePen: https://codepen.io/ahandsel/pen/QWGrOya
Reference: Client on Node.js: Uncaught ReferenceError: require is not defined