Skip to content Skip to sidebar Skip to footer

Error: Summernote Is Not A Function When Using Local Files

I am having a really odd problem. When I used my local summernote files to load the text editor, '.summernote is not a function' happened. However, if I used the cdn files to load

Solution 1:

I don't think you're including your scripts in the right order.

When you loaded from the CDN, your order looked something like this:

<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.js"></script>
<script src="javascript/common.js" type="text/javascript"></script>

. . . which is logical, because you want to be sure that summernote is loaded by the time your main JS code executes.

However, your PHP dependency management code was injecting the tags linking to local files after that same script. Basically, dump all of that logic before your customer's script too:

<?php if ($styles) { ;?>
    <?php foreach ($styles as $style) { ;?>
        <link href="<?php echo $style;?>" rel="stylesheet"></link>
    <?php } ;?>
<?php } ;?>
<?php if ($scripts) { ;?>
    <?php foreach ($scripts as $script) { ;?>
        <script src="<?php echo $script;?>" type="text/javascript"></script>
    <?php } ;?>
<?php } ;?>

<script src="javascript/common.js" type="text/javascript"></script>

(Also note that in your PHP you wrote href instead of src for your script tag generation.)


Solution 2:

For me, I wanted to use summer note with bootstrap4, I copied the below code from the official documentation but it didn't work, I realized afterwards that I was embedding a newer bootstrap version at the beginning of my page (I was reaching out to some bootstrap files located at the assets), I removed that line and everything went just fine:

 <script src="https://code.jquery.com/jquery-3.5.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.js"></script>

Post a Comment for "Error: Summernote Is Not A Function When Using Local Files"