I’m trying to include a custom Language Package with Lezer into an CodeMirror 6 editor. However, the editor doesn’t show up so far. Instead, I get this error:
Uncaught Error: Unrecognized extension value in extension set ([object Object]). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.
inner file:///.../CodeMirrorProblems/editor-example/editor.bundle.js:2020
inner file:///.../CodeMirrorProblems/editor-example/editor.bundle.js:1995
inner file:///.../CodeMirrorProblems/editor-example/editor.bundle.js:2021
inner file:///.../CodeMirrorProblems/editor-example/editor.bundle.js:1995
inner file:///.../CodeMirrorProblems/editor-example/editor.bundle.js:2021
inner file://.../CodeMirrorProblems/editor-example/editor.bundle.js:1995
flatten$1 file://.../CodeMirrorProblems/editor-example/editor.bundle.js:2024
resolve file:///.../CodeMirrorProblems/editor-example/editor.bundle.js:1932
create file:///.../CodeMirrorProblems/editor-example/editor.bundle.js:2759
EditorView file:///.../CodeMirrorProblems/editor-example/editor.bundle.js:10629
<anonymous> file:///.../CodeMirrorProblems/editor-example/editor.bundle.js:38297
<anonymous> file:///.../CodeMirrorProblems/editor-example/editor.bundle.js:38302
editor.bundle.js:2020:26
Steps to Produce:
- Set up a custom Language Package in the local directory
CodeMirrorProblems/lang-example
:- Clone the Language Package Template from the Git Example Repository.
- Replace all occurrences of
EXAMPLE
withDummy
. - Bundle with
npm run prepare
.
- Set up an Editor as described in the Bundling Tutorial:
- Create a new directory,
CodeMirrorProblems/editor-example
. - Add
editor.mjs
andindex.html
as described. - Set up a new Node.js module and add CodeMirror,
@codemirror/lang-javascript
. and Rollup dev dependencies. - Bundle with
node_modules/.bin/rollup editor.mjs -f iife -o editor.bundle.js \ -p @rollup/plugin-node-resolve
. At this point, the JavaScript Editor works.
- Create a new directory,
- Try to include the Language Package:
- Modify the
editor.mjs
file to use the Dummy Language Package. - Link the Language Package to use in the Editor project.
- Bundle the Editor with Rollup.
- Modify the
My editor.mjs
now:
import {EditorView, basicSetup} from "codemirror"
import {Dummy} from "codemirror-lang-dummy"
let editor = new EditorView({
extensions: [basicSetup, Dummy()],
parent: document.body
})
My package.json
for the Editor:
{
"name": "editor-example",
"version": "1.0.0",
"description": "CodeMirror example that will use a language example definition.",
"main": "editor.js",
"scripts": {
"prepare": "rollup editor.mjs -f iife -o editor.bundle.js -p @rollup/plugin-node-resolve"
},
"author": "bjthehun",
"license": "ISC",
"dependencies": {
"@codemirror/lang-javascript": "^6.1.7",
"codemirror": "^6.0.1",
"codemirror-lang-dummy": "file:../lang-example"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.2",
"rollup": "^3.21.0"
}
}
My package.json
for the Language Package:
{
"name": "codemirror-lang-dummy",
"version": "0.1.0",
"description": "Dummy language support for CodeMirror",
"scripts": {
"test": "mocha test/test.js",
"prepare": "rollup -c"
},
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"types": "dist/index.d.ts",
"sideEffects": false,
"dependencies": {
"@codemirror/language": "^6.0.0",
"@lezer/highlight": "^1.0.0",
"@lezer/lr": "^1.0.0"
},
"devDependencies": {
"@lezer/generator": "^1.0.0",
"mocha": "^9.0.1",
"rollup": "^2.60.2",
"rollup-plugin-dts": "^4.0.1",
"rollup-plugin-ts": "^3.0.2",
"typescript": "^4.3.4"
},
"license": "MIT"
}