sweetalert_1.default is not a function : Angular 5


I’m about discovering SweetAlert in the official link , so i wanted to use it in my app angular5 .

i have installed it this way :

npm install sweetalert --save

I have imported it in my component : edit-client.component with this :

  import swal from 'sweetalert';

Here is the file editClient.component.ts where i tried to use it :

import swal from 'sweetalert';

  selector: 'app-edit-clients',
  templateUrl: './edit-clients.component.html',
  styleUrls: ['./edit-clients.component.scss']
export class EditClientsComponent implements OnInit {


        swal('mise a jour effecture !');

        this.router.navigate([ '../../../list' ], { relativeTo: this.activatedRoute });


But while running this exemple , i can’t see the alert and i get an error instead :

RROR TypeError: sweetalert_1.default is not a function
    at SafeSubscriber.eval [as _next] (edit-clients.component.ts:39)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:240)
    at SafeSubscriber.next (Subscriber.js:187)
    at Subscriber._next (Subscriber.js:128)
    at Subscriber.next (Subscriber.js:92)

What i’m doing wrong ?


For those who faced the same problem i imported instead :

import * as _swal from 'sweetalert';
import { SweetAlert } from 'sweetalert/typings/core';
const swal: SweetAlert = _swal as any;

And used then :

swal('hello world'); 

this fixed the issue.

Answered By – dEs12ZER

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.