Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cannot bundle with rollup as suggested in codemirror docs #4

Open
frabjous opened this issue Jul 6, 2023 · 1 comment
Open

Cannot bundle with rollup as suggested in codemirror docs #4

frabjous opened this issue Jul 6, 2023 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@frabjous
Copy link

frabjous commented Jul 6, 2023

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

  • codemirror v 6.0.1
  • lang-tex 0.0.3
  • @rollup/plugin-node-resolve 15.1.0
  • rollup 3.26.2

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.

@frabjous frabjous added the question Further information is requested label Jul 6, 2023
@AHaliq
Copy link

AHaliq commented Jul 24, 2023

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants