noraj
noraj

Reputation: 4632

sweetalert2 TypeError: this is undefined after v8 upgrade

I moved from sweetalert2 ^7.32.4 → ^8.11.7, I read the v8.0.0 breaking changes and none of my code directly call one of the impacted functions.

I wonder what is causing this mysterious error: (TypeError: this is undefined)

enter image description here

Upvotes: 3

Views: 1310

Answers (2)

G. Verni
G. Verni

Reputation: 707

As reported in the SweetAlert2 release note for version 8.0.0 referenced at the top of the README, this major version release introduced a breaking change in the way the Swal is invoked. In the release note there is also a link to the reason why this breaking change has been introduced.

The changelog is actually including this breaking change under the title "BREAKING CHANGE: remove withNoNewKeyword enhancer". The content of this commit explains:

From now on the recommended way to use SweetAlert2 is: Swal.fire({...options})

Upvotes: 5

noraj
noraj

Reputation: 4632

I went to see the new documentation examples, and they are all launching the popup with Swal.fire() when before Swal() alone was valid.

The problem is that if you check CHANGELOG.md for fire you don't see any mentions of that function. But this is a breaking change as it was earlier not mandatory and now is.

Here is the fix for my specific problem.

Upvotes: 2

Related Questions