react-codemirror2 icon indicating copy to clipboard operation
react-codemirror2 copied to clipboard

JavaScript linting error :- window.JSHINT not defined, CodeMirror JavaScript linting cannot run

Open sarthakkundra opened this issue 4 years ago • 2 comments

I can't seem to get the linting to work for javaScript mode. I read about a similar JSON linting issue from this repo only but that also doesn't seem to solve the problem. When my component mounts I get the error mentioned in the title in the console. I have scraped through all the files of the package and I think I have imported everything that needs to be imported. Here's the code for my react component. Any help will be appreciated :)

 import React from "react";
import { UnControlled as CodeMirror } from "react-codemirror2";

import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/material.css';
import 'codemirror/addon/lint/lint.css';
import 'codemirror/addon/hint/show-hint.css';



require('codemirror/mode/javascript/javascript.js');
require('codemirror/addon/lint/javascript-lint');
require('codemirror/addon/lint/lint.js');
require('codemirror/addon/hint/javascript-hint');


const JsEditor = ({code}) => {
  return (
    <div>
      <CodeMirror
        value={code}
        options={{
          gutters: ["CodeMirror-lint-markers"],
          lint: true,
          mode: "javascript",
          theme: "material",
          lineNumbers: true,
          lineWrapping: true,
          readOnly: true,
         
        }}
       
      />
    </div>
  );
};

export default JsEditor;  

sarthakkundra avatar Jul 24 '20 19:07 sarthakkundra

The following two lines have solved my problem. hope they can help you. import { JSHINT } from "jshint"; window.JSHINT = JSHINT;

kk-fan avatar Jan 19 '22 06:01 kk-fan

thank you, it works for me

coderzym avatar Oct 10 '22 07:10 coderzym