sweet-alert icon indicating copy to clipboard operation
sweet-alert copied to clipboard

Install issue with Laravel 7

Open timgavin opened this issue 4 years ago • 1 comments

I followed the installation instructions but I continue to receive the js error

can't find variable: swal

bootstrap.js

...
try {
    window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');

    require('bootstrap');
    require('sweetalert');
} catch (e) {}
...

app.js

require('./bootstrap');

$( document ).ready(function() {
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
});

app.blade

...
    @include('sweet::alert')
</body>

Then I run npm run prod

The only way I can get it to work is if I use the CDN....

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

timgavin avatar Mar 29 '20 17:03 timgavin

In your bootstrap.js, try adding this to your try catch block:

const swal = require('sweetalert');

chuysb avatar Jul 13 '20 16:07 chuysb