Can CodeMirror be loaded in a "safe" / isolated mode?


Something is causing the following error:

Uncaught TypeError: CodeMirror.multiplexingMode is not a function

I’m building a JS file with the following script:

#!/usr/bin/env bash

uglifyjs --verbose --timings --compress \
    --output=plugin_src/js/codemirror-compressed.js \
    node_modules/codemirror/lib/codemirror.js \
    node_modules/codemirror/addon/mode/multiplex.js \
    node_modules/codemirror/addon/display/fullscreen.js \
    node_modules/codemirror/addon/display/placeholder.js \
    node_modules/codemirror/mode/css/css.js \
    node_modules/codemirror/mode/javascript/javascript.js \
    node_modules/codemirror/mode/xml/xml.js \
    node_modules/codemirror/mode/htmlmixed/htmlmixed.js \

The weird part to this issue is this:

I’m using CodeMirror in a custom-built WordPress plugin.
When using it in my local dev setup, it works fine.
When using on a production WordPress website, same version, with the same plugin, the error is shown in JS console.

It’s very difficult to replicate the same WordPress environment with all the themes and plugins and configurations locally, so I’d rather try to isolate my CodeMirror script and its addons and make it impossible for other scripts to affect it.

Is there any way I can load CodeMirror in a safe mode, like e.g. jQuery plugin can.

Here’s how I use CodeMirror. multiplexingMode:

jQuery(function() {

// ...

// Custom CodeMirror mode that combines HTML and Twig
    CodeMirror.defineMode("twig_html", function (config) {
        return CodeMirror.multiplexingMode (
            CodeMirror.getMode(config, "text/html"), {
                open: /\{[\{%#]/, close: /[}%#]\}/,
                mode: CodeMirror.getMode(config, "twig"),
                parseDelimiters: true


Even after full page load, when I type typeof CodeMirror.multiplexingMode in my local environment, it returns “function”, but on live website, it returns undefined.

Also, it’s obvious some other plugin or theme is using CodeMirror of an older version:





So because I cannot control what other plugins / themes will be installed on a website, I’d rather load CodeMirror in an isolated mode and use my version for my needs, and let other code use another version for its needs.

One idea was to compile from sources, but I can’t seem to find sources for e.g. CodeMirror.multiplexingMode to further compile it in a single JS file with a bundler.

addon/mode/multiplex.js does not look like a source, it looks like a compiled module, and accesses the global CodeMirror variable. Any ideas?