Hi All,
I am just getting started with CodeMirror 6 and am just trying to create a basic example. However, I keep running into this error:
Unrecognized extension value in extension set ([object Object]). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.
I have already tried removing package-lock and reinstalling node_modules, but this did not work. I have also ensured that all of my codemirror state versions are the same:
├─┬ @codemirror/autocomplete@6.8.1
│ └── @codemirror/state@6.2.1 deduped
├─┬ @codemirror/commands@6.2.4
│ └── @codemirror/state@6.2.1 deduped
├─┬ @codemirror/lang-html@6.4.5
│ ├─┬ @codemirror/lang-css@6.2.0
│ │ └── @codemirror/state@6.2.1 deduped
│ └── @codemirror/state@6.2.1 deduped
├─┬ @codemirror/lang-javascript@6.1.9
│ ├─┬ @codemirror/lint@6.4.0
│ │ └── @codemirror/state@6.2.1 deduped
│ └── @codemirror/state@6.2.1 deduped
├─┬ @codemirror/language@6.8.0
│ └── @codemirror/state@6.2.1 deduped
├─┬ @codemirror/search@6.5.0
│ └── @codemirror/state@6.2.1 deduped
├── @codemirror/state@6.2.1
├─┬ @codemirror/view@6.14.1
│ └── @codemirror/state@6.2.1 deduped
└─┬ codemirror@6.0.1
└── @codemirror/state@6.2.1 deduped
Here’s my simple example:
import React, {useRef, useEffect} from 'react';
import {EditorView} from "codemirror"
import {EditorState} from "@codemirror/state"
import {tags} from "@lezer/highlight"
import {lineNumbers} from "@codemirror/view"
import {HighlightStyle} from "@codemirror/language"
let myHighlightStyle = HighlightStyle.define([
{ tag: tags.keyword, color: "#569cd6" },
{ tag: tags.comment, color: "#6a9955" },
]);
function TestComponent({ code, editorRef }) {
const editorDiv = useRef(null);
useEffect(() => {
if (editorDiv.current) {
const view = new EditorView({
state: EditorState.create({
doc: code,
extensions: [
lineNumbers(),
myHighlightStyle,
],
}),
parent: editorDiv.current,
});
editorRef.current = view;
return () => {
// Cleanup editor on unmount
view.destroy();
};
}
}, [code, language]);
return <div ref={editorDiv} style={{ height: "100%", width: "100%" }} />;
}
Does anyone know what causes this error or how to fix it? I looked at other posts about this error, but none of them seemed to fix the issue.