I am finishing a JS view and found an error when testing it on the server. I believe it is generated by KNIME when importing the libraries with RequireJS.
The view is using CodeMirror (CodeMirror 5 User Manual) to produce some text editors for some scripts in textareas. CodeMirror includes some extra JS sources for syntax highlighting, themes and other plugins. In this view so far I used two syntaxes: R and Markdown. The structure of the library is something like:
- lib/ folder with JS and CSS
- mode/ folder with syntax highlighters
There are more folders but for my needs now these are enough. Anyway, CodeMirror does not work when the node is in a wrapped metanode (to be used in the server) and produces the error:
Failed to load resource: net::ERR_FILE_NOT_FOUND
require.js:143 Uncaught Error: Script error for "codemirror/../../lib/codemirror", needed by: codemirror/r
http://requirejs.org/docs/errors.html#scripterror
at makeError (require.js:168)
at HTMLScriptElement.onScriptError (require.js:1738)
The same JS view does work when the node is not wrapped. The configuration in the pluginās feature.xml is:
<webResourceBundle debug="false" name="codemirror" usesDefine="true" version="5.9.2" webResourceBundleID="codemirror">
<webResource relativePathSource="js-lib/codemirror/" relativePathTarget="codemirror"</webResource>
<importResource relativePath="codemirror/codemirror.js" type="JAVASCRIPT" />
<importResource relativePath="codemirror/codemirror.css" type="CSS" />
<importResource relativePath="codemirror/r.js" type="JAVASCRIPT" />
<!-- <importResource relativePath="codemirror/markdown.js" type="JAVASCRIPT" /> -->
</webResourceBundle>
In CodeMirrorās user manual there is a warning about RequireJS:
Do not use RequireJSā
paths
option to configure the path to CodeMirror, since it will break loading submodules through relative paths. Use thepackages
configuration option instead, as in:
require.config({
packages: [{
name: "codemirror",
location: "../path/to/codemirror",
main: "lib/codemirror"
}]
});
Thus, my guess is the relativePaths in the webResourceBundle are breaking somehow the submodules. It is just a guess, I have not yet checked the source code. Is there any way to work around it? Or could it be fixed?
Thanks,
Miguel