react-codemirror2
react-codemirror2 copied to clipboard
JavaScript linting error :- window.JSHINT not defined, CodeMirror JavaScript linting cannot run
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;
The following two lines have solved my problem. hope they can help you.
import { JSHINT } from "jshint"; window.JSHINT = JSHINT;
thank you, it works for me