CodeSeven / toastr

Simple javascript toast notifications
http://www.toastrjs.com
MIT License
11.9k stars 2.04k forks source link

TypeError: Cannot read properties of undefined (reading 'extend') #694

Closed voaneves closed 7 months ago

voaneves commented 1 year ago

Hey there.

I'm using the CDN version of the JS and CSS and tried to have a button like this:

          <button
            onclick="toastr['success']('Are you the six fingered man?')"
          >
          </button>

And I got this:

toastr.min.js:1 Uncaught TypeError: Cannot read properties of undefined (reading 'extend') at m (toastr.min.js:1:4693) at Object.i [as success] (toastr.min.js:1:432) at HTMLButtonElement.onclick (index.unformatted.html:532:33)

Am I doing anything wrong? I tried to import JQuery too, to no avail.

Thanks!

Tootle-likes-code commented 1 year ago

I've got this too, using the CDN link in an ASP.NET Core application.

@if (TempData["error"] != null)
{
    <script src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
    <script type="text/javascript">
        toastr.error('@TempData["error"]');
    </script>
}

Error in console:

toastr.js:474 Uncaught TypeError: Cannot read properties of undefined (reading 'extend') at m (toastr.js:474:40) at Object.i [as success] (toastr.js:474:40) at Category:54:16

MatyiFKBT commented 7 months ago

According to the README, jQuery is required. Make sure to import jQuery before toastr, something like this worked for me:

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>