Can't bundle lang-tex

Hi everyone. I’m a newbie to Codemirror v6, and I’m a dabbler not a programmer, so bear with me.

I’m trying to enable lang-tex from this repository.

Here is a simple example that already generates the problem:


import {EditorView, basicSetup} from "codemirror";
import {texSyntax} from "lang-tex";

let editor = new EditorView({
    extensions: [basicSetup, texSyntax()],
    parent: document.getElementById("editorparent")
});

export default editor;

When I run the bundler:

node_modules/.bin/rollup test.mjs -f iife -o editor.bundle.js -p @rollup/plugin-node-resolve

I get this output:

test.mjs → editor.bundle.js...
(!) "this" has been rewritten to "undefined"
https://rollupjs.org/troubleshooting/#error-this-is-undefined
node_modules/lang-tex/lib/index.js
1: "use strict";
2: var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
                          ^
3:     if (k2 === undefined) k2 = k;
4:     Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
...and 3 other occurrences
[!] RollupError: "texSyntax" is not exported by "node_modules/lang-tex/lib/index.js", imported by "test.mjs".
https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module
test.mjs (2:8)
1: import {EditorView, basicSetup} from "codemirror";
2: import {texSyntax} from "lang-tex";
           ^
3:
4: let editor = new EditorView({
    at error (/home/kck/http/typesetting/open-guide-editor/node_modules/rollup/dist/shared/rollup.js:349:30)
    at Module.error (/home/kck/http/typesetting/open-guide-editor/node_modules/rollup/dist/shared/rollup.js:15061:16)
    at Module.traceVariable (/home/kck/http/typesetting/open-guide-editor/node_modules/rollup/dist/shared/rollup.js:15486:29)
    at ModuleScope.findVariable (/home/kck/http/typesetting/open-guide-editor/node_modules/rollup/dist/shared/rollup.js:14011:39)
    at Identifier.bind (/home/kck/http/typesetting/open-guide-editor/node_modules/rollup/dist/shared/rollup.js:9731:40)
    at CallExpression.bind (/home/kck/http/typesetting/open-guide-editor/node_modules/rollup/dist/shared/rollup.js:7351:23)
    at CallExpression.bind (/home/kck/http/typesetting/open-guide-editor/node_modules/rollup/dist/shared/rollup.js:11297:15)
    at ArrayExpression.bind (/home/kck/http/typesetting/open-guide-editor/node_modules/rollup/dist/shared/rollup.js:7347:28)
    at Property.bind (/home/kck/http/typesetting/open-guide-editor/node_modules/rollup/dist/shared/rollup.js:7351:23)
    at ObjectExpression.bind (/home/kck/http/typesetting/open-guide-editor/node_modules/rollup/dist/shared/rollup.js:7347:28)


Exit code:  1

I’m hoping I’m just doing something simple wrongly. But I’ve been struggling in general understanding many of the intricacies of v6

Or is there another extension that provides LaTeX language support?

1 Like

I’m getting a similar issue, im also using typescript so I also get this warning of a type mismatch

Type 'LezerSyntax' is not assignable to type 'Extension'.
  Type 'LezerSyntax' is not assignable to type '{ extension: Extension; }'.
    Types of property 'extension' are incompatible.
      Type 'import("./node_modules/.pnpm/@codemirror+next@0.13.1/node_modules/@codemirror/next/state/src/facet").Extension' is not assignable to type 'import("./node_modules/.pnpm/@codemirror+state@6.2.1/node_modules/@codemirror/state/dist/index").Extension'.
        Type '{ [isExtension]: true; }' is not assignable to type 'Extension'.ts(2322)

This is ancient. Try using the current version of the libraries (and mind the way some of the stuff was merged into other packages—if the current version is 0.x, it no longer exists).

@AHaliq Maybe I’m just bad at reading such output, but that doesn’t look like a similar problem to me. It seems to have to do with a completely different package.

Anyway, I get the problem I described in the original post using up-to-date everything, at least as far as I can tell. I reported the problem in the repo’s bug tracker here, but that was weeks ago and there’s been no response. It doesn’t seem to be actively developed, which is a shame, because I don’t think there’s any other package supporting TeX/LaTeX in Codemirror 6.

got it, the lang-tex v0.0.3 package is using codemirror/next package and not the latest; 6.0.1. we can see this in lang-tex@0.0.3_lezer@0.13.5/node_modules/lang-tex/lib/tex.d.ts or see definition for texSyntax. The lang-tex package maintainers have to update their codemirror deps

// tex.d.ts
import { TagSystem } from "@codemirror/next/highlight";
import { LezerSyntax } from "@codemirror/next/syntax";
...

edit: this code is from the lezer package which is depreceated and needs to be replaced by lezer/lr