Sweetalert: ERROR TypeError: sweetalert_1.default is not a function

Created on 1 Feb 2018  路  6Comments  路  Source: t4t5/sweetalert

Hi, my sweet alert modal is not showing and I'm getting this error on the console:

ERROR TypeError: sweetalert_1.default is not a function

image

I'm using Angular v5 and SweetAlert 2.1.0.

I'm importing it with the following code:

import swal from 'sweetalert';

And I'm trying to show a simple alert with the following code:

swal("Hello world!");

Any tips?

Most helpful comment

I found the error:

I was importing it like the above code, as the documentation says but I had to import it with the following code:

import * as sweetalert from 'sweetalert';
sweetalert("Hello world!");

I couldnt user "swal" alias for some reason. Typings I guess. This way works fine.

All 6 comments

I found the error:

I was importing it like the above code, as the documentation says but I had to import it with the following code:

import * as sweetalert from 'sweetalert';
sweetalert("Hello world!");

I couldnt user "swal" alias for some reason. Typings I guess. This way works fine.

image

no me sirve

bueno sirve pero me da ese error

Same error. Nothing changes, even with @rafamds approach. His approach gives:

Cannot invoke an expression whose type lacks a call signature. Type 'typeof "/home/khophi/Developments/Angular/PackageToMe/node_modules/sweetalert/typings/sweetalert"' has no compatible call signatures

@seanmavley take a look at #799, this might be a duplicate of that issue.

@lionralfs thanks for pointing out. I was just about to reference that issue in this thread. The #799 solution you presented is working fine here too.

Thanks.

Was this page helpful?
0 / 5 - 0 ratings