codemirror / codemirror5

In-browser code editor (version 5, legacy)
http://codemirror.net/5/
MIT License
26.86k stars 4.97k forks source link

Cannot register lint helper when importing commonjs modules #6362

Open joker-777 opened 4 years ago

joker-777 commented 4 years ago

Hi, this is the way how I import and initialize codemirror right now

import CodeMirror from "codemirror"
import "codemirror/lib/codemirror.css"
import "codemirror/addon/lint/lint"
import "codemirror/addon/lint/lint.css"

CodeMirror.fromTextArea(textarea, {
  lint: true,
  mode: "yaml"
}

CodeMirror.registerHelper("lint", "yaml", yaml_linter)

Before I was using a global instance window.CodeMirror where yaml_linter was used correctly but now it doesn't work anymore. It works though when I use:

CodeMirror.registerGlobalHelper("lint", "yaml", () => true, yaml_linter)
marijnh commented 4 years ago

CodeMirror doesn't support an ES module interface, so there's going to be a bunch of bundler magic happening here that I can't see through. If you can reproduce this in a CommonJS setup, I can take a look.

joker-777 commented 3 years ago

Thanks for your answer. I hope that at one point you will also support ES modules. Any reason why you haven't done it yet?

marijnh commented 3 years ago

See https://codemirror.net/6/. The 5.x branch is never going to support ES modules, because with the current approach to modularity that'd create either a bunch of duplication or a breaking change.

joker-777 commented 3 years ago

Thanks for pointing to it. I didn't know that you are working on a new version.