mathematic-inc / codemirror-tex

A monorepo for all TeX-related CodeMirror projects
GNU General Public License v3.0
11 stars 2 forks source link

Cannot bundle with rollup as suggested in codemirror docs #4

Open frabjous opened 1 year ago

frabjous commented 1 year ago

Overview.

I am getting an error with this package when trying to make use of it in a codemirror project.

I'm a newbie to codemirror, and just a dabbler not a full time programmer so bear with me.

The error for me can be produced as easily as the following:

Steps to reproduce.

  1. Create a new project with npm init.

  2. Install codemirror and rollup/@rollup-plugin-node-resolve along with this project: npm install codemirror lang-tex rollup @rollup/plugin-node-resolve.

  3. Create a javascript module that loads the package. I can get the problem with something as simple as this:

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

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

export default editor;
  1. Try to use rollup to bundle the dependencies needed for codemirror with this extension, using node_modules/.bin/rollup editor.mjs -f iife -o editor.bundle.js -p @rollup/plugin-node-resolve as suggested here.

When I do so I get this output:

editor.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 "editor.mjs".
https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module
editor.mjs (3:8)
1:
2: import {EditorView, basicSetup} from "codemirror";
3: import {texSyntax} from "lang-tex";
           ^
4:
5: let editor = new EditorView({
    at error (/home/frabjous/tmp/textest/node_modules/rollup/dist/shared/rollup.js:349:30)
    at Module.error (/home/frabjous/tmp/textest/node_modules/rollup/dist/shared/rollup.js:15073:16)
    at Module.traceVariable (/home/frabjous/tmp/textest/node_modules/rollup/dist/shared/rollup.js:15498:29)
    at ModuleScope.findVariable (/home/frabjous/tmp/textest/node_modules/rollup/dist/shared/rollup.js:14023:39)
    at Identifier.bind (/home/frabjous/tmp/textest/node_modules/rollup/dist/shared/rollup.js:9743:40)
    at CallExpression.bind (/home/frabjous/tmp/textest/node_modules/rollup/dist/shared/rollup.js:7363:23)
    at CallExpression.bind (/home/frabjous/tmp/textest/node_modules/rollup/dist/shared/rollup.js:11309:15)
    at ArrayExpression.bind (/home/frabjous/tmp/textest/node_modules/rollup/dist/shared/rollup.js:7359:28)
    at Property.bind (/home/frabjous/tmp/textest/node_modules/rollup/dist/shared/rollup.js:7363:23)
    at ObjectExpression.bind (/home/frabjous/tmp/textest/node_modules/rollup/dist/shared/rollup.js:7359:28)

The expected behavior is that I not get this error, and that I be able to use the extension in a simple codemirror instance.

It's possible I just didn't install things right. Again, newbie.

Versions

I did get a lot of deprecation warnings about lezer packages when installing lang-tex, which may or may not be relevant.

Note I posted about this in the codemirror discussion forum here but didn't get any replies.

AHaliq commented 1 year ago

hey guys, may I know which version of codemirror was working for this extension?

otherwise to use the latest 6.0.1 requires replacing the lezer dep with @lezer/lr. as seen here https://www.npmjs.com/package/lezer