Search code examples
javascripthtmlcodemirror

Javascript using CodeMirror.js Error: Uncaught ReferenceError: CodeMirror is not defined


I get this error shown in the browser, when trying to create an Code-Editor with HTML and the JavaScript Library 'CodeMirror':

Uncaught ReferenceError: CodeMirror is not defined
    at index.html?_ijt=2cf0kfsr3jnpb58d7jndumktte:68

But considering, that I linked then in my index.html, I am unable to figure out whats wrong:

<!--  CodeMirror  -->
    <link rel="stylesheet" href="codemirror/CodeMirror-master/CodeMirror-master/lib/codemirror.css">
    <script type="module" src="codemirror/CodeMirror-master/CodeMirror-master/src/codemirror.js"></script>
    <script type="module" src="codemirror/CodeMirror-master/CodeMirror-master/mode/javascript/javascript.js"></script>

Do I have to use node.js if I want to include this library in my code?

EDIT:

I changed the files which I added to another version and now only receive one error:

Uncaught ReferenceError: CodeMirror is not defined
    at index.html?_ijt=knaua520sd7qi1kst4958cmse4:74

HTML-Code:

    <link rel="stylesheet" href="codemirror/codemirror-5.61.0/lib/codemirror.css">
    <script type="module" src="codemirror/codemirror-5.61.0/lib/codemirror.js"></script>
    <script type="module" src="codemirror/codemirror-5.61.0/mode/javascript/javascript.js"></script>

Solution

  • I fixed the issue:

    <link rel="stylesheet" href="codemirror/codemirror-5.61.0/lib/codemirror.css">
        <script src="codemirror/codemirror-5.61.0/lib/codemirror.js"></script>
        <script src="codemirror/codemirror-5.61.0/mode/javascript/javascript.js"></script>
    

    So, to fix this, you have to either make type="text/javascript" or to remove this parameter, because this is it's default value.